﻿using Ledict.CaseLibrary.Common;
using Ledict.ConditionExtract.BLL;
using Ledict.ConditionExtract.Common;
using Ledict.ConditionExtract.Model;
using Ledict.Utility.Helper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace Ledict.ConditionExtract.Frm.NodeTree
{
    [ComVisible(true)]
    public partial class ElementsConfig : Form
    {

        #region 构造单例
        //静态锁
        private static readonly object Lock = new object();
        /// <summary>
        /// 单例
        /// </summary>
        private static ElementsConfig _instance;
        /// <summary>
        /// 返回单例
        /// </summary>
        public static ElementsConfig Instance
        {
            get
            {
                if (_instance == null || _instance.IsDisposed)
                {
                    lock (Lock)
                    {
                        if (_instance == null || _instance.IsDisposed)
                        {
                            _instance = new ElementsConfig();
                        }
                    }
                }
                return _instance;
            }

        }
        #endregion

        //逻辑，在主界面添加数据时，弹出具体的流程，选择流程后进入该流程绑定的模块，然后对该模块进行配置，在数据库中不再保存流程字段，只保存模块字段，默认配置是对属性配置来说的，
        //当在属性配置中配置了属性配置的方式后，在切换到属性配置后，如果有默认的配置，则直接把默认配置关联到当前配置中，如果修改默认配置，则创建一个新的配置关联到配置表中
        //在添加时，新增了一个IsXinZeng字段来标识，在删除时，如果是新增的，则不需要从数据库里面删除，直接删除即可。
        //0：表示该xpath在案件类型上进行了通用配置；1表示当前数据为卷宗转换中配置

        /// <summary>
        /// ExtractFeature表dll         
        /// </summary>
        ExtractFeatureBLL extractFeatureBll = new ExtractFeatureBLL();

        Sys_CourtBLL sysCourtBll = new Sys_CourtBLL();
        //法院数据表
        private static DataTable sysCourtTable = new DataTable();

        CaseCauseBLL caseCauseBll = new CaseCauseBLL();
        //案由数据表
        private static DataTable sysCaseCauseTable = new DataTable();

        SYS_CaseTypeBLL sysCaseTypeBll = new SYS_CaseTypeBLL();
        //案件类型数据表
        private static DataTable sysCaseTypeTable = new DataTable();

        SYS_CaseType_DocTypeBLL sysDocTypeBll = new SYS_CaseType_DocTypeBLL();
        //卷宗类型数据表
        private static DataTable sysDocTypeTable = new DataTable();
        //卷宗类型数据表
        private static DataTable sysDocTypeTableAll = new DataTable();
        RuleInfosBLL ruleInfoBll = new RuleInfosBLL();

        private static string url = ConfigHelper.AppSettings("ElementsConfigPath");
        private static string urlNew = ConfigHelper.AppSettings("ElementsRuleConfigPath");


        private TreeNode clicknode;//点击节点树后，保存该节点
        private TreeNode clicknodeConfig;//点击节点树后，保存该节点

        private TreeNode editnode;//点击获得当前节点

        Dictionary<string, string[]> numbers = new Dictionary<string, string[]>();
        NewIDBLL newid = new NewIDBLL();
        private static bool isAdd = false;

        ReturnModeBLL returnModelBll = new ReturnModeBLL();
        ConvertModeBLL convertModelBll = new ConvertModeBLL();
        ArgumentRelBLL argumentRelBll = new ArgumentRelBLL();
        SYS_ArgumentBLL sysArgumentBll = new SYS_ArgumentBLL();
        ElementExtractSourceBLL elementExtractSourceBll = new ElementExtractSourceBLL();

        private ReturnMode rm = new ReturnMode();
        private ElementExtractSource ees = new ElementExtractSource();
        private ConvertMode cm = new ConvertMode();
        private ExtractFeature extractFeature = new ExtractFeature();
        private ExtractInfo extractInfo = new ExtractInfo();
        public static DataTable sysArgumentTypeData = new DataTable();
        private string isBenShen = string.Empty;
        private string FDContent;
        private bool IsXinZeng = false;
        public static Dictionary<string, string> dicYaoSu = new Dictionary<string, string>();
        public static Dictionary<string, List<parameters>> dicYaoSuParams = new Dictionary<string, List<parameters>>();
        public static int addNum = 0;
        ExtractFeatureBLL efBll = new ExtractFeatureBLL();

        DataTable dtXS = new DataTable();
        static string selectLICheng = string.Empty;
        static string CaseType = string.Empty;


        //逻辑分段节点树上显示出来的所有节点集合
        private List<TreeNode> ParagraphNodeLists = new List<TreeNode>();
        //案件要素中心节点树上显示出来的所有节点集合
        private List<TreeNode> CaseExtractionNodeLists = new List<TreeNode>();
        //关键词搜索后的节点集合
        List<TreeNode> selectNodes = new List<TreeNode>();
        //CM_CMode 0关联案件字典 1函数 2函数sql 3关联案由字典

        /// <summary>
        /// 流程配置文件文件名称
        /// </summary>
        private string filePathName;

        WebUtil webMethod = new WebUtil();
        public ElementsConfig()
        {
            InitializeComponent();
            cmbCXFS.SelectedIndex = 0;
            Control.CheckForIllegalCrossThreadCalls = false;
            panelElement.Visible = true;
            panelElement.Dock = DockStyle.Fill;
            panelElementCofig.Visible = false;
            panelElementCofig.Dock = DockStyle.None;
            webBrowerUser1.SaveSuccess += ShowMessage;
        }

        #region 加载事件
        private void ElementsConfig_Load(object sender, EventArgs e)
        {
            //加载案由数据
            //LoadSysCaseCauseData();
            //加载案件类型数据
            LoadSysCaseTypeData();
            //加载系统应用数据
            //GetCallSysCfgData();
            LoadYaoSuDatas();
            dgvYaoSu.AutoGenerateColumns = false;
            sysArgumentTypeData = sysArgumentBll.GetSYS_ArgumentTypeData();
            sysCaseCauseTable = caseCauseBll.GetSysCaseCauseData();

            dtXS.Columns.AddRange(new DataColumn[] { new DataColumn("EF_ID"), new DataColumn("ModuleName"), new DataColumn("ModulePath") });

            //Dictionary<string, string> getData = new Dictionary<string, string>();
            //CommonMsgNew1 cm = WebUtil.DoGet<CommonMsgNew1>(url + "api/WebApi/GetSpecialFunDataAnalysis", getData, "gb2312");
            //if (cm.Code== "1")
            //{
            //    string s1 = cm.CfgContent;
            //    res f1 = Newtonsoft.Json.JsonConvert.DeserializeObject<res>(s1);
            //    f1.fun.Count
            //}
            sysDocTypeTableAll = sysDocTypeBll.GetSysCaseTypeDocType();

        } 
        #endregion

        private void LoadYaoSuDatas()
        {
            dicYaoSu.Clear();
            dicYaoSuParams.Clear();
            Dictionary<string, string> getData = new Dictionary<string, string>();
            getData.Add("fileFullName", @"config\dataEngineCommonFunsCfg\dataenginecommonfunlistconfig.json");

            //getData.Add("fileFullName", @"config\dataEngineCommonFunsCfg\dataEngineCommonFunListConfig.json");

            WordParseAPIReturnModel cm1 = WebUtil.DoGetNew<WordParseAPIReturnModel>(url + "api/WordParse/GetConfigFileContent", getData, "gb2312");

            //Dictionary<string, string> getData = new Dictionary<string, string>();
            //WordParseAPIReturnModel cm1 = WebUtil.DoGetNew<WordParseAPIReturnModel>(url + "api/WordParse/GetSpecialFunDataAnalysis", getData, "gb2312");
            if (cm1.result.code.ToString() == "1")
            {
                string s1 = cm1.body.ToString();
                var f1 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<fun>>(s1);
                if (f1.Count > 0)
                {
                    foreach (fun item in f1)
                    {
                        if (!dicYaoSu.ContainsKey(item.name.Trim()))
                        {
                            dicYaoSu.Add(item.name.Trim(), item.remark.Trim() + "," + item.cmode.Trim());
                            if (item.parameters != null && item.parameters.Count > 0)
                            {
                                dicYaoSuParams.Add(item.name.Trim(), item.parameters);
                            }
                        }
                    }
                }
            }
        }



        /// <summary>
        /// 法院数据展开节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_AfterExpand(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            DataTable dt = new DataTable();
            if (sysCourtTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").Length > 0)
            {
                dt = sysCourtTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        TreeNode node = new TreeNode { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        if (sysCourtTable.Select(" ParentID='" + node.Tag.ToString() + "' ").Length > 0)
                        {
                            DataTable dtt = sysCourtTable.Select(" ParentID='" + node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                            if (dtt != null && dtt.Rows.Count > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                        }
                        e.Node.Nodes.Add(node);
                    }
                }
            }
        }





        /// <summary>
        /// 案由数据展开节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_AfterExpandCaseCause(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            DataTable dt = new DataTable();
            if (sysCaseCauseTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").Length > 0)
            {
                dt = sysCaseCauseTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        TreeNode node = new TreeNode { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        if (sysCaseCauseTable.Select(" ParentID='" + node.Tag.ToString() + "' ").Length > 0)
                        {
                            DataTable dtt = sysCaseCauseTable.Select(" ParentID='" + node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                            if (dtt != null && dtt.Rows.Count > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                        }
                        e.Node.Nodes.Add(node);
                    }
                }
            }
        }




        /// <summary>
        /// 加载案件类型数据
        /// </summary>
        private void LoadSysCaseTypeData()
        {
            sysCaseTypeTable = sysCaseTypeBll.GetCaseTypeData();
            if (sysCaseTypeTable.Rows.Count > 0)
            {
                if (sysCaseTypeTable.Select("ParentID is null  or ParentID='' ").Length > 0)
                {
                    DataTable sysCaseTypedt = sysCaseTypeTable.Select("ParentID is null or ParentID='' ").CopyToDataTable<DataRow>();
                    foreach (DataRow dr in sysCaseTypedt.Rows)
                    {
                        TreeNode node = new TreeNode() { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        if (sysCaseTypeTable.Select("  ParentID='" + node.Tag.ToString() + "' ").Length > 0)
                        {
                            node.Nodes.Add(new TreeNode());
                        }
                        cbTreeViewCaseType.TreeView.Nodes.Add(node);
                    }
                    cbTreeViewCaseType.DropDownStyle = ComboBoxStyle.DropDown;
                    cbTreeViewCaseType.TreeView.AfterExpand += TreeView_AfterExpandCaseType;
                    cbTreeViewCaseType.TreeView.AfterCheck += TreeView_AfterCheck;
                }
            }
        }

        /// <summary>
        /// 案件类型数据选中事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_AfterCheck(object sender, TreeViewEventArgs e)
        {
            LoadCaseDocType();
        }

        private void LoadCaseDocType()
        {
            if (!string.IsNullOrEmpty(cbTreeViewCaseType.Text) && sysCaseTypeTable.Select(" ID='" + cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString() + "' ").Length > 0)
            {
                cbTreeViewDocType.Text = "";
                cbTreeViewDocType.TreeView.Nodes.Clear();
                string code = sysCaseTypeTable.Select(" ID='" + cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString() + "' ")[0]["Code"].ToString();
                sysDocTypeTable = sysDocTypeBll.GetSysDocTypeDataByCaseTypeID(code);
                if (sysDocTypeTable != null && sysDocTypeTable.Rows.Count > 0)
                {

                    foreach (DataRow dr in sysDocTypeTable.Rows)
                    {
                        TreeNode node = new TreeNode() { Text = dr["Name"].ToString() + "-" + dr["ID"].ToString(), Tag = dr["ID"].ToString() };
                        cbTreeViewDocType.TreeView.Nodes.Add(node);
                    }
                }
            }

        }

        /// <summary>
        /// 案件类型展开节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TreeView_AfterExpandCaseType(object sender, TreeViewEventArgs e)
        {
            e.Node.Nodes.Clear();
            DataTable dt = new DataTable();
            if (sysCaseTypeTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").Length > 0)
            {
                dt = sysCaseTypeTable.Select(" ParentID='" + e.Node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                if (dt != null && dt.Rows.Count > 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        TreeNode node = new TreeNode { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
                        if (sysCaseTypeTable.Select(" ParentID='" + node.Tag.ToString() + "' ").Length > 0)
                        {
                            DataTable dtt = sysCaseTypeTable.Select(" ParentID='" + node.Tag.ToString() + "' ").CopyToDataTable<DataRow>();
                            if (dtt != null && dtt.Rows.Count > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                        }
                        e.Node.Nodes.Add(node);
                    }
                }
            }
        }

        /// <summary>
        /// 案件类型文本框改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbTreeViewCaseType_TextUpdate(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cbTreeViewCaseType.Text))
            {
                if (sysCaseTypeTable.Select("Name like '%" + cbTreeViewCaseType.Text + "%'").Length > 0)
                {
                    DataTable dt3 = sysCaseTypeTable.Select("Name like '%" + cbTreeViewCaseType.Text + "%'").CopyToDataTable<DataRow>();
                    cbTreeViewCaseType.TreeView.Nodes.Clear();
                    if (dt3 != null && dt3.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt3.Rows.Count; i++)
                        {
                            TreeNode node = new TreeNode();
                            node.Text = dt3.Rows[i]["Name"].ToString();
                            node.Tag = dt3.Rows[i]["ID"].ToString();
                            if (sysCaseTypeTable.Select("ParentID='" + node.Tag + "'").Length > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                            cbTreeViewCaseType.TreeView.Nodes.Add(node);
                        }
                    }
                }
                else
                {
                    cbTreeViewCaseType.TreeView.Nodes.Clear();
                }
            }
            else
            {
                cbTreeViewCaseType.TreeView.Nodes.Clear();
                LoadSysCaseTypeData();
            }
        }

        /// <summary>
        /// 卷宗类型文本框改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbTreeViewDocType_TextUpdate(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cbTreeViewDocType.Text))
            {
                if (sysDocTypeTable.Select("Name like '%" + cbTreeViewDocType.Text + "%'").Length > 0)
                {
                    DataTable dt3 = sysDocTypeTable.Select("Name like '%" + cbTreeViewDocType.Text + "%'").CopyToDataTable<DataRow>();
                    cbTreeViewDocType.TreeView.Nodes.Clear();
                    if (dt3 != null && dt3.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt3.Rows.Count; i++)
                        {
                            TreeNode node = new TreeNode();
                            node.Text = dt3.Rows[i]["Name"].ToString();
                            node.Tag = dt3.Rows[i]["ID"].ToString();
                            if (sysCaseTypeTable.Select("ParentID='" + node.Tag + "'").Length > 0)
                            {
                                node.Nodes.Add(new TreeNode());
                            }
                            cbTreeViewDocType.TreeView.Nodes.Add(node);
                        }
                    }
                }
                else
                {
                    cbTreeViewDocType.TreeView.Nodes.Clear();
                }
            }
            else
            {
                cbTreeViewDocType.TreeView.Nodes.Clear();
                LoadCaseDocType();
            }
        }


        Dictionary<string, string> dicc = new Dictionary<string, string>();
        /// <summary>
        /// 根据选择条件获取数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetData_Click(object sender, EventArgs e)
        {
            lblLCShow.Visible = false;
            lblLiuCheng.Text = "";
            tvTxtParagraph.Nodes.Clear();
            tvElementData.Nodes.Clear();
            clicknodeConfig = null;
            if (string.IsNullOrEmpty(cbTreeViewCaseType.Text) || cbTreeViewCaseType.TreeView.SelectedNode == null)
            {
                MessageBox.Show("请选择案件类型！");
                cbTreeViewCaseType.Focus();
                return;
            }
            //有卷宗类型走默认要素配置
            if (!string.IsNullOrEmpty(cbTreeViewDocType.Text) && cbTreeViewDocType.TreeView.SelectedNode != null)
            {
                panelElement.Visible = true;
                panelElement.Dock = DockStyle.Fill;
                panelElementCofig.Visible = false;
                panelElementCofig.Dock = DockStyle.None;

                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                string docType = cbTreeViewDocType.TreeView.SelectedNode.Tag.ToString();
                CaseType = caseType;

                PublicMethod.ClearDataGridViewData(dgvYS);
                PublicMethod.ClearDataGridViewData(dgvFD);
                PublicMethod.ClearDataGridViewData(dgvArgument);
                PublicMethod.ClearDataGridViewData(dgvArgumentType);
                PublicMethod.ClearDataGridViewData(dgvDataReturn);
                PublicMethod.ClearDataGridViewData(dgvHanShuConfig);
                PublicMethod.ClearDataGridViewData(dgvArgumentTypeConfig);
                PublicMethod.ClearDataGridViewData(dgvArgumentConfig);
                PublicMethod.ClearDataGridViewData(dgvYaoSu);
                //chromiumWebBrowser1.Load("about:blank");

                Dictionary<string, string> getData = new Dictionary<string, string>();
                getData.Add("caseType", caseType);
                getData.Add("docType", docType);

                // http://192.168.1.52:10004/api/WordParse/GetProcessModuleConfig?caseType=b1&docType=mssuitbook
                CommonMsg cm = WebUtil.DoGet<CommonMsg>(url + "api/WordParse/GetProcessModuleConfig", getData, "gb2312");
                if (cm.result.code == "0")
                {
                    tvTxtParagraph.Nodes.Clear();
                    tvElementData.Nodes.Clear();
                    MessageBox.Show("获取接口数据发生错误：" + cm.result.message);
                }
                else if (cm.result.code == "1")
                {
                    string str = cbTreeViewCaseType.TreeView.SelectedNode.FullPath.ToString().Split(new char[] { '\\' })[0];
                    caseType = sysCaseTypeTable.Select(" Name='" + str + "' ")[0]["Code"].ToString();
                    getData = new Dictionary<string, string>();
                    getData.Add("caseType", caseType);
                    WordParseAPIReturnModel cm1 = WebUtil.DoGet<WordParseAPIReturnModel>(url + "api/WordParse/GetElementNodesCode", getData, "UTF-8");
                    if (cm1.result.code == "0" && cm1.body != null)
                    {
                        string strNew = (PublicMethod.DeCodeBase64new(65001, cm1.body.ToString())).Replace("{", "").Replace("}", "".Replace("\r\n", ""));
                        if (!string.IsNullOrEmpty(strNew))
                        {
                            dicc.Clear();
                            string[] stt = strNew.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                            if (stt.Length > 0)
                            {
                                foreach (var item in stt)
                                {
                                    if (item == "\r\n")
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        dicc.Add(item.Split(new char[] { ':' })[0].Replace("@", "").Replace("/", "\\").Trim(), item.Split(new char[] { ':' })[1].Trim());
                                    }
                                }
                            }
                        }
                    }
                    DataTable ProcessPaths = new DataTable();
                    ProcessPaths.Columns.AddRange(new DataColumn[] { new DataColumn("Name"), new DataColumn("Code") });
                    Dictionary<string, List<ModuleInfoMode>> dic = new Dictionary<string, List<ModuleInfoMode>>();
                    List<body> bd = cm.body;
                    if (bd.Count > 0)
                    {
                        foreach (body item in bd)
                        {
                            if (!string.IsNullOrEmpty(item.ProcessPath))
                            {
                                DataRow dr = ProcessPaths.NewRow();
                                dr["Code"] = item.ProcessPath;
                                dr["Name"] = "流程名称：" + item.ProcessName + " 路径：" + item.ProcessPath;
                                ProcessPaths.Rows.Add(dr);
                                if (!dic.ContainsKey(item.ProcessPath))
                                {
                                    dic.Add(item.ProcessPath, item.ModuleInfos);
                                }
                            }
                        }
                        if (ProcessPaths.Rows.Count > 0)
                        {
                            ConfigSelect cs = new ConfigSelect(ProcessPaths);
                            cs.ShowDialog();
                            if (cs.DialogResult == DialogResult.Yes && !string.IsNullOrEmpty(cs.Code))
                            {
                                if (dic.ContainsKey(cs.Code))
                                {
                                    selectLICheng = cs.Code;
                                    lblLCShow.Visible = true;
                                    lblLiuCheng.Text = selectLICheng;
                                    numbers.Clear();
                                    List<ModuleInfoMode> modules = dic[cs.Code];
                                    foreach (ModuleInfoMode item in modules)
                                    {
                                        if (item.ModuleCode == "LdtDataEngin.Moudle.MoudleParagraphExtract")
                                        {
                                            if (!numbers.ContainsKey("Paragraph"))
                                            {
                                                numbers.Add("Paragraph", new string[] { item.ModuleName, item.ModulePath });

                                            }
                                            if (!string.IsNullOrEmpty(item.ModuleConfigContent.Trim()))
                                            {
                                                ParagraphNodeLists.Clear();
                                                FDContent = item.ModuleConfigContent.Trim();
                                                XmlToTree(item.ModuleConfigContent.Trim(), tvTxtParagraph, 0);
                                            }

                                        }
                                        else if (item.ModuleCode == "LdtDataEngin.Moudle.MoudleCaseExtract")
                                        {
                                            if (!numbers.ContainsKey("CaseExtraction"))
                                            {
                                                numbers.Add("CaseExtraction", new string[] { item.ModuleName, item.ModulePath });
                                            }
                                            if (!string.IsNullOrEmpty(item.ModuleConfigContent.Trim()))
                                            {
                                                CaseExtractionNodeLists.Clear();
                                                XmlToTreeNew(item.ModuleConfigContent.Trim(), tvElementData, 1);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        #region MyRegion
                        //JsonTool jt = new JsonTool();
                        //foreach (moduleConfig item in bd.moduleConfig)
                        //{
                        //    if (item.number == "0")
                        //    {
                        //        filePathName = item.filePath;
                        //        XmlDocument xl = new XmlDocument();
                        //        xl.LoadXml(item.configContent);
                        //        XmlNodeList xls = xl.GetElementsByTagName("step");
                        //        foreach (XmlNode item1 in xls)
                        //        {
                        //            if (((XmlElement)item1).Attributes["code"].Value == "LdtDataEngin.Moudle.MoudleParagraphExtract")
                        //            {
                        //                if (!numbers.ContainsKey(((XmlElement)item1).Attributes["number"].Value))
                        //                {
                        //                    numbers.Add("Paragraph", new string[] { ((XmlElement)item1).Attributes["number"].Value.ToString(), ((XmlElement)item1).Attributes["executecode"].Value.ToString() });

                        //                }
                        //            }
                        //            if (((XmlElement)item1).Attributes["code"].Value == "LdtDataEngin.Moudle.MoudleCaseExtract")
                        //            {
                        //                if (!numbers.ContainsKey(((XmlElement)item1).Attributes["number"].Value))
                        //                {
                        //                    numbers.Add("CaseExtraction", new string[] { ((XmlElement)item1).Attributes["number"].Value.ToString(), ((XmlElement)item1).Attributes["executecode"].Value.ToString() });
                        //                }
                        //            }
                        //        }
                        //        break;
                        //    }
                        //}
                        //foreach (moduleConfig item in bd.moduleConfig)
                        //{
                        //    //if (numbers.ContainsKey("Paragraph") && item.number == numbers["Paragraph"][0].ToString())
                        //    //{
                        //    //    FDContent = item.configContent;
                        //    //    if (!string.IsNullOrEmpty(FDContent.Trim()))
                        //    //        XmlToTree(item.configContent, tvTxtParagraph, 0);
                        //    //    //tvTxtParagraph.ExpandAll();
                        //    //}
                        //    //else if (numbers.ContainsKey("CaseExtraction") && item.number == numbers["CaseExtraction"][0].ToString())
                        //    //{
                        //    //    // XmlToTree(item.moduleName,item.filePath,item.configDetail[0].configContent, tvElementData, 1);
                        //    //    //2019-10-25 臨時添加      
                        //    //    if (item.configDetail != null && !string.IsNullOrEmpty(item.configDetail[0].configContent.Trim()))
                        //    //        XmlToTree(item.configDetail[0].configContent, tvElementData, 1);
                        //    //}
                        //} 
                        #endregion
                    }
                    else
                    {
                        MessageBox.Show("未找到对应的流程配置文件！");
                        return;
                    }
                }
            }
            else
            {
                //无卷宗类型设置走要素属性默认配置
                panelElement.Visible = false;
                panelElement.Dock = DockStyle.None;
                panelElementCofig.Visible = true;
                panelElementCofig.Dock = DockStyle.Fill;

                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                //行政执法案件特殊处理
                if (cbTreeViewCaseType.TreeView.SelectedNode.Text == "行政执法案件")
                {
                    string caseTypeParent = "";
                    caseTypeParent = caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                    Dictionary<string, string> getData = new Dictionary<string, string>();
                    getData.Add("fileFullName", @"config\casetypestructconfig\" + caseTypeParent + "\\" + caseType + ".xml");

                    WordParseAPIReturnModel cm = WebUtil.DoGetNew<WordParseAPIReturnModel>(url + "api/WordParse/GetConfigFileContent", getData, "gb2312");
                    if (cm.result.code == "0")
                    {
                        tvElementsConfig.Nodes.Clear();
                        MessageBox.Show("获取接口数据发生错误：" + cm.result.message);
                    }
                    else if (cm.result.code == "1")
                    {
                        string elementConfig = cm.body.ToString();
                        if (!string.IsNullOrEmpty(elementConfig))
                        {
                            XmlToTree(elementConfig, tvElementsConfig, 1);
                        }
                        cbxConvertModeConfig.SelectedIndex = 0;
                        cbxConvertModeConfig_SelectedIndexChanged(null, null);
                    }
                }
                else
                if (cbTreeViewCaseType.TreeView.SelectedNode.Parent != null)
                {

                    string fullPath = cbTreeViewCaseType.TreeView.SelectedNode.FullPath;
                    string caseTypeParent = fullPath.Substring(0, fullPath.IndexOf('\\'));
                    caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                    caseTypeParent = sysCaseTypeTable.Select(" Name='" + caseTypeParent + "' ")[0]["Code"].ToString();
                    Dictionary<string, string> getData = new Dictionary<string, string>();
                    getData.Add("fileFullName", @"config\casetypestructconfig\" + caseTypeParent + "\\" + caseType + ".xml");

                    WordParseAPIReturnModel cm = WebUtil.DoGetNew<WordParseAPIReturnModel>(url + "api/WordParse/GetConfigFileContent", getData, "gb2312");
                    if (cm.result.code == "0")
                    {
                        tvElementsConfig.Nodes.Clear();
                        MessageBox.Show("获取接口数据发生错误：" + cm.result.message);
                    }
                    else if (cm.result.code == "1")
                    {
                        string elementConfig = cm.body.ToString();
                        if (!string.IsNullOrEmpty(elementConfig))
                        {
                            XmlToTree(elementConfig, tvElementsConfig, 1);
                        }
                        cbxConvertModeConfig.SelectedIndex = 0;
                        cbxConvertModeConfig_SelectedIndexChanged(null, null);
                    }
                }


            }


        }

        private void LoadSysCaseTypeConfig()
        {
            //sysCaseTypeTable = sysCaseTypeBll.GetCaseTypeData();
            //if (sysCaseTypeTable.Rows.Count > 0)
            //{
            //    if (sysCaseTypeTable.Select("ParentID is null  or ParentID='' ").Length > 0)
            //    {
            //        DataTable sysCaseTypedt = sysCaseTypeTable.Select("ParentID is null or ParentID='' ").CopyToDataTable<DataRow>();
            //        TreeNode commonNode = new TreeNode() { Text = "common", Tag = "common" };
            //        cbTreeViewCaseTypeConfig.TreeView.Nodes.Add(commonNode);
            //        foreach (DataRow dr in sysCaseTypedt.Rows)
            //        {
            //            TreeNode node = new TreeNode() { Text = dr["Name"].ToString(), Tag = dr["ID"].ToString() };
            //            if (sysCaseTypeTable.Select("  ParentID='" + node.Tag.ToString() + "' ").Length > 0)
            //            {
            //                node.Nodes.Add(new TreeNode());
            //            }
            //            cbTreeViewCaseTypeConfig.TreeView.Nodes.Add(node);
            //        }
            //        cbTreeViewCaseTypeConfig.DropDownStyle = ComboBoxStyle.DropDown;
            //        cbTreeViewCaseTypeConfig.TreeView.AfterExpand += TreeView_AfterExpandCaseType;
            //    }
            //}
        }

        /// <summary>
        /// xml转树
        /// </summary>
        /// <param name="xml">需要转的xml结构</param>
        /// <param name="tv">树控件</param>
        /// <param name="tag">标记</param>
        public void XmlToTree(string xml, TreeView tv, int tag)
        {
            tv.Nodes.Clear();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlElement root = doc.DocumentElement;
            if (tag == 0)
            {
                TreeNode tn = new TreeNode() { Text = root.GetAttribute("explain"), Tag = "", Name = Guid.NewGuid().ToString() };
                ParagraphNodeLists.Add(tn);
                foreach (XmlNode subXmlNod in root.ChildNodes)
                {
                    //2022-02-14邓婕提出将步骤编码code改为执行代码executecode
                    //((XmlElement)subXmlNod).GetAttribute("code") 
                    TreeNode tn1 = new TreeNode() { Text = ((XmlElement)subXmlNod).GetAttribute("zh_cn"), Tag = ((XmlElement)subXmlNod).GetAttribute("executecode") + "!" + ((XmlElement)subXmlNod).GetAttribute("code"), Name = tn.Name + "," + Guid.NewGuid().ToString() };
                    tn.Nodes.Add(tn1);
                    ParagraphNodeLists.Add(tn1);
                    TransXml(subXmlNod.ChildNodes, tn1, 0);
                }
                tv.Nodes.Add(tn);
            }
            else if (tag == 1)
            {
                TreeNode tn2 = new TreeNode() { Text = root.Name };
                if (((XmlElement)root).HasAttributes)
                {
                    foreach (XmlAttribute item in ((XmlElement)root).Attributes)
                    {
                        TreeNode attributeNode = new TreeNode() { Text = item.Name };
                        tn2.Nodes.Add(attributeNode);
                    }
                }
                foreach (XmlNode item in root.ChildNodes)
                {
                    TreeNode tn = new TreeNode() { Text = ((XmlElement)item).Name };
                    if (((XmlElement)item).HasAttributes)
                    {
                        foreach (XmlAttribute ite in ((XmlElement)item).Attributes)
                        {
                            TreeNode attributeNode = new TreeNode() { Text = ite.Name };
                            tn.Nodes.Add(attributeNode);
                        }
                    }
                    TransXml(item.ChildNodes, tn, 1);
                    tn2.Nodes.Add(tn);
                }
                tv.Nodes.Add(tn2);
            }
        }

        /// <summary>
        /// 转换xml
        /// </summary>
        /// <param name="xmlNodes">xml节点</param>
        /// <param name="parent">树节点</param>
        /// <param name="tag">标记</param>
        /// <param name="tuples">传入参数</param>
        public void TransXml(XmlNodeList xmlNodes, TreeNode parent, int tag, Tuple<string, string> tuples = null)
        {
            foreach (XmlNode xmlNod in xmlNodes)
            {
                if (tag == 0)
                {
                    TreeNode subNod = new TreeNode() { Text = ((XmlElement)xmlNod).GetAttribute("zh_cn"), Tag = ((XmlElement)xmlNod).GetAttribute("executecode") + "!" + ((XmlElement)xmlNod).GetAttribute("code"), Name = parent.Name + "," + Guid.NewGuid().ToString() };
                    parent.Nodes.Add(subNod);
                    ParagraphNodeLists.Add(subNod);
                    if (xmlNod.ChildNodes.Count > 0)
                    {
                        TransXml(xmlNod.ChildNodes, subNod, 0, tuples);
                    }
                }
                else if (tag == 1)
                {
                    TreeNode subNod1 = new TreeNode() { Text = ((XmlElement)xmlNod).Name, Tag = tuples, Name = parent.Name + "," + Guid.NewGuid().ToString() };
                    parent.Nodes.Add(subNod1);
                    CaseExtractionNodeLists.Add(subNod1);

                    if (((XmlElement)xmlNod).HasAttributes)
                    {
                        foreach (XmlAttribute item in ((XmlElement)xmlNod).Attributes)
                        {
                            TreeNode attributeNode = new TreeNode() { Text = item.Name, Tag = tuples, Name = parent.Name + "," + Guid.NewGuid().ToString() };
                            subNod1.Nodes.Add(attributeNode);
                            CaseExtractionNodeLists.Add(attributeNode);
                        }
                    }
                    if (xmlNod.ChildNodes.Count > 0)
                    {
                        TransXml(xmlNod.ChildNodes, subNod1, 1, tuples);
                    }
                }
            }
        }

        /// <summary>
        /// xml转树新方法
        /// </summary>
        /// <param name="xml">需要转换xml</param>
        /// <param name="tv">树控件</param>
        /// <param name="tag">标记</param>
        public void XmlToTreeNew(string xml, TreeView tv, int tag)
        {
            tv.Nodes.Clear();
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);
            XmlElement root = doc.DocumentElement;
            if (tag == 0)
            {
                TreeNode tn = new TreeNode() { Text = root.GetAttribute("explain"), Tag = "", Name = Guid.NewGuid().ToString() };
                foreach (XmlNode subXmlNod in root.ChildNodes)
                {
                    //2022-02-14邓婕提出将步骤编码code改为执行代码executecode
                    //((XmlElement)subXmlNod).GetAttribute("code") 
                    TreeNode tn1 = new TreeNode() { Text = ((XmlElement)subXmlNod).GetAttribute("zh_cn"), Tag = ((XmlElement)subXmlNod).GetAttribute("code"), Name = tn.Name + "," + Guid.NewGuid().ToString() };
                    tn.Nodes.Add(tn1);
                    TransXmlNew(subXmlNod.ChildNodes, tn1, 0);
                }
                tv.Nodes.Add(tn);
            }
            else if (tag == 1)
            {
                TreeNode tn2 = new TreeNode() { Text = root.Name, Name = Guid.NewGuid().ToString() };
                CaseExtractionNodeLists.Add(tn2);

                if (((XmlElement)root).HasAttributes)
                {
                    foreach (XmlAttribute item in ((XmlElement)root).Attributes)
                    {
                        TreeNode attributeNode = new TreeNode() { Text = item.Name, Name = tn2.Name + "," + Guid.NewGuid().ToString() };
                        tn2.Nodes.Add(attributeNode);
                        CaseExtractionNodeLists.Add(attributeNode);
                    }
                }
                foreach (XmlNode item in root.ChildNodes)
                {
                    TreeNode tn = new TreeNode() { Text = ((XmlElement)item).Name, Name = tn2.Name + "," + Guid.NewGuid().ToString() };
                    CaseExtractionNodeLists.Add(tn);
                    if (((XmlElement)item).HasAttributes)
                    {
                        foreach (XmlAttribute ite in ((XmlElement)item).Attributes)
                        {
                            TreeNode attributeNode = new TreeNode() { Text = ite.Name, Name = tn.Name + "," + Guid.NewGuid().ToString() };
                            tn.Nodes.Add(attributeNode);
                            CaseExtractionNodeLists.Add(attributeNode);
                        }
                    }
                    TransXmlNew(item.ChildNodes, tn, 1);
                    tn2.Nodes.Add(tn);
                }
                tv.Nodes.Add(tn2);
            }
        }

        public void TransXmlNew(XmlNodeList xmlNodes, TreeNode parent, int tag, Tuple<string, string> tuples = null)
        {
            foreach (XmlNode xmlNod in xmlNodes)
            {
                if (tag == 0)
                {
                    TreeNode subNod = new TreeNode() { Text = ((XmlElement)xmlNod).GetAttribute("zh_cn"), Tag = ((XmlElement)xmlNod).GetAttribute("code"), Name = parent.Name + "," + Guid.NewGuid().ToString() };
                    parent.Nodes.Add(subNod);
                    if (xmlNod.ChildNodes.Count > 0)
                    {
                        TransXml(xmlNod.ChildNodes, subNod, 0, tuples);
                    }
                }
                else if (tag == 1)
                {
                    TreeNode subNod1 = new TreeNode() { Text = ((XmlElement)xmlNod).Name, Tag = tuples, Name = parent.Name + "," + Guid.NewGuid().ToString() };
                    parent.Nodes.Add(subNod1);
                    CaseExtractionNodeLists.Add(subNod1);
                    if (((XmlElement)xmlNod).HasAttributes)
                    {
                        foreach (XmlAttribute item in ((XmlElement)xmlNod).Attributes)
                        {
                            TreeNode attributeNode = new TreeNode() { Text = item.Name, Tag = tuples, Name = parent.Name + "," + Guid.NewGuid().ToString() };
                            subNod1.Nodes.Add(attributeNode);
                            CaseExtractionNodeLists.Add(attributeNode);
                        }
                    }
                    if (xmlNod.ChildNodes.Count > 0)
                    {
                        TransXml(xmlNod.ChildNodes, subNod1, 1, tuples);
                    }
                }
            }
        }

        /// <summary>
        /// 逻辑分段和案件要素中心树选择节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tvTxtParagraph_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (clicknode != null)
            {
                if (clicknode.Name != e.Node.Name)
                {
                    if (dgvYaoSu.Rows.Count > 0 && IsXinZeng)
                    {
                        MessageBox.Show("请将节点" + clicknode.Text + "配置完整保存后再试！");
                        return;
                    }
                    clicknode.ForeColor = Color.Black;
                }
                else if (clicknode.Name == e.Node.Name)
                {

                    return;
                }
            }
            if (e.Node != null)
            {
                clicknode = e.Node;//保存节点
                clicknode.ForeColor = Color.Red;
                PublicMethod.ClearDataGridViewData(dgvYS);
                PublicMethod.ClearDataGridViewData(dgvFD);
                PublicMethod.ClearDataGridViewData(dgvArgument);
                PublicMethod.ClearDataGridViewData(dgvArgumentType);
                PublicMethod.ClearDataGridViewData(dgvDataReturn);
                PublicMethod.ClearDataGridViewData(dgvYaoSu);
                //chromiumWebBrowser1.Load("about:blank");
                rm = new ReturnMode();
                ees = new ElementExtractSource();
                cm = new ConvertMode();
                extractFeature = new ExtractFeature();
                extractInfo = new ExtractInfo();
                IsXinZeng = false;
                LoadYaoSuData();
                if (dgvYaoSu.Rows.Count == 1 && !string.IsNullOrEmpty(extractInfo.EXI_ID))
                {
                    isAdd = true;
                    switch (tabControlConfig.SelectedTab.Text)
                    {
                        case "规则配置":
                            LoadElementExtractSourceData();
                            break;
                        case "规则提取":
                            dgvYaoSu_CellContentClick(null, null);
                           
                            break;
                        case "属性配置":
                            cbxConvertMode.SelectedIndex = 0;
                            cbxConvertMode_SelectedIndexChanged(null, null);
                            break;
                        case "数据返回方式":
                            LoadReturnModeData();
                            break;
                    }
                }
                else
                {
                    isAdd = false;
                }


            }
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadYaoSuData()
        {
            string tabName = tabControlModule.SelectedTab.Text;
            DataTable dt = new DataTable();
            string[] number = new string[] { };
            if (tabName == "逻辑分段")
            {
                number = numbers["Paragraph"];
                dt = extractFeatureBll.GetExtractFeatureData(string.IsNullOrEmpty(clicknode.Tag.ToString()) ? "" : clicknode.Tag.ToString().Split('!')[1].ToString(), 0, numbers["Paragraph"][0].ToString());
            }
            else if (tabName == "案件要素中心")
            {
                number = numbers["CaseExtraction"];
                dt = extractFeatureBll.GetExtractFeatureData(clicknode.FullPath.ToString(), 1, numbers["CaseExtraction"][0].ToString());
            }
            if (dt != null && dt.Rows.Count > 0)
            {
                dtXS.Clear();
                DataRow dr = dtXS.NewRow();
                dr["EF_ID"] = dt.Rows[0]["EF_ID"].ToString();
                dr["ModuleName"] = dt.Rows[0]["EF_ModuleCode"].ToString();
                dr["ModulePath"] = number[1].ToString();
                dtXS.Rows.Add(dr);

                extractInfo.EXI_ParagraCode = dt.Rows[0]["EXI_ParagraCode"].ToString();
                extractInfo.EXI_DataMode = Convert.ToInt32(dt.Rows[0]["EXI_DataMode"].ToString());
                extractInfo.EXI_ID = dt.Rows[0]["EXI_ID"].ToString();

                extractFeature.EF_ID = dt.Rows[0]["EF_ID"].ToString();
                extractFeature.EF_ModuleCode = dt.Rows[0]["EF_ModuleCode"].ToString();
                extractFeature.EES_ID = dt.Rows[0]["EES_ID"].ToString();
                extractFeature.RIU_ID = dt.Rows[0]["RIU_ID"].ToString();
                extractFeature.CM_ID = dt.Rows[0]["CM_ID"].ToString();
                extractFeature.RM_ID = dt.Rows[0]["RM_ID"].ToString();
                dgvYaoSu.DataSource = dtXS;
                LoadElementExtractSourceData();
            }
        }

        /// <summary>
        /// 节点关系配置添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (clicknode != null && dgvYaoSu.Rows.Count == 0)
            {
                IsXinZeng = true;
                string tabName = tabControlModule.SelectedTab.Text;
                string nodeName = string.Empty;
                string[] number = new string[] { };
                if (tabName == "逻辑分段")
                {
                    extractInfo.EXI_DataMode = 2;
                    nodeName = extractInfo.EXI_ParagraCode = clicknode.Tag.ToString().Split('!')[1].ToString(); ;
                    number = numbers["Paragraph"];
                }
                else if (tabName == "案件要素中心")
                {
                    extractInfo.EXI_DataMode = 1;
                    nodeName = extractInfo.EXI_XmlPath = clicknode.FullPath.ToString();
                    number = numbers["CaseExtraction"];
                }
                extractFeature.EF_ID = newid.CreateID("ExtractFeature");
                string exiID = extractFeatureBll.GetExtractInfoData(nodeName, extractInfo.EXI_DataMode);
                if (!string.IsNullOrEmpty(exiID))
                {
                    extractInfo.EXI_ID = exiID;
                }
                else
                {
                    extractInfo.EXI_ID = newid.CreateID("ExtractInfo");
                }
                extractFeature.EXI_ID = extractInfo.EXI_ID;
                extractFeature.EF_ModuleCode = number[0].ToString();

                dtXS.Clear();
                DataRow dr = dtXS.NewRow();
                dr["EF_ID"] = extractFeature.EF_ID;
                dr["ModuleName"] = number[0].ToString();
                dr["ModulePath"] = number[1].ToString();
                dtXS.Rows.Add(dr);
                dgvYaoSu.DataSource = dtXS;
                tabControlConfig.SelectTab(tabPage3);

                #region MyRegion
                //MembershipConfig mc = new MembershipConfig();
                //string tabName = tabControlModule.SelectedTab.Text;
                //if (tabName == "逻辑分段")
                //{
                //    mc.NodeName = clicknode.Tag.ToString();
                //    mc.TabName = 0;
                //    mc.MudelName = numbers["Paragraph"][1].ToString();
                //    mc.FileName = filePathName;
                //}
                //else if (tabName == "案件要素中心")
                //{
                //    mc.NodeName = clicknode.FullPath.ToString();
                //    mc.TabName = 1;
                //    mc.MudelName = numbers["CaseExtraction"][1].ToString();
                //    mc.FileName = filePathName;
                //    //mc.Tuples = clicknode.Tag as Tuple<string, string>;
                //}
                //var dialogResult = mc.ShowDialog();
                //if (dialogResult == DialogResult.Yes)
                //{
                //    if (mc.CheckTable != null && mc.CheckTable.Rows.Count == 1)
                //    {
                //        mc.CheckTable.Columns.Add("xuhao");
                //        mc.CheckTable.Rows[0]["xuhao"] = "1";
                //        mc.CheckTable.Columns.Add("IsPublic");
                //        if (!string.IsNullOrEmpty(mc.CheckTable.Rows[0]["EES_ID"].ToString()))
                //        {
                //            mc.CheckTable.Rows[0]["IsPublic"] = "是";
                //            extractFeature.EES_ID = mc.CheckTable.Rows[0]["EES_ID"].ToString();
                //            extractFeature.RIU_ID = mc.CheckTable.Rows[0]["RIU_ID"].ToString();
                //            extractFeature.CM_ID = mc.CheckTable.Rows[0]["CM_ID"].ToString();
                //            extractFeature.RM_ID = mc.CheckTable.Rows[0]["RM_ID"].ToString();
                //            extractFeature.EF_ID = newid.CreateID("ExtractFeature");
                //            extractInfo.EXI_ID = newid.CreateID("ExtractInfo");
                //            extractFeature.EXI_ID = extractInfo.EXI_ID;
                //        }
                //        else
                //        {
                //            mc.CheckTable.Rows[0]["IsPublic"] = "否";
                //            extractFeature.EF_ID = newid.CreateID("ExtractFeature");
                //            extractInfo.EXI_ID = newid.CreateID("ExtractInfo");
                //            extractFeature.EXI_ID = extractInfo.EXI_ID;
                //        }
                //        isBenShen = mc.CheckTable.Rows[0]["IsBenShen"].ToString();
                //        mc.CheckTable.Rows[0]["EF_ID"] = extractFeature.EF_ID;
                //        dgvYaoSu.DataSource = mc.CheckTable;
                //        extractFeature.EF_FeatureName = mc.FileName;
                //        if (tabName == "逻辑分段")
                //        {
                //            extractInfo.EXI_DataMode = 2;
                //            extractInfo.EXI_ModuleCode = mc.MudelName;
                //            extractInfo.EXI_ParagraCode = mc.NodeName;
                //        }
                //        else if (tabName == "案件要素中心")
                //        {
                //            extractInfo.EXI_DataMode = 1;
                //            extractInfo.EXI_XmlPath = mc.NodeName;
                //            extractInfo.EXI_ModuleCode = mc.MudelName;
                //        }
                //        if (mc.CheckTable.Rows[0]["IsConfig"].ToString() == "否")
                //        {
                //            IsXinZeng = true;
                //        }
                //        if (mc.CheckTable.Rows[0]["IsConfig"].ToString() == "是")
                //        {
                //            IsXinZeng = true;
                //            LoadElementExtractSourceData();
                //        }
                //    }
                //    tabControlConfig.SelectTab(tabPage3);
                //}
                //else if (dialogResult == DialogResult.No)
                //{
                //    return;
                //} 
                #endregion
            }
            else
            {
                MessageBox.Show("请先选择节点或者删除模块数据后再试！");
                return;
            }

        }

        /// <summary>
        /// 逻辑分段、案件要素中心切页改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabControlModule_SelectedIndexChanged(object sender, EventArgs e)
        {
            tvElementData.SelectedNode = tvTxtParagraph.SelectedNode = null;
            if (clicknode != null)
            {
                clicknode.ForeColor = Color.Black;
                clicknode = null;
            }
            if (tabControlModule.SelectedIndex == 0)
            {
                dgvFD.Visible = true;
                dgvYS.Visible = false;
            }
            else if (tabControlModule.SelectedIndex == 1)
            {
                dgvYS.Visible = true;
                dgvFD.Visible = false;
            }
            PublicMethod.ClearDataGridViewData(dgvYS);
            PublicMethod.ClearDataGridViewData(dgvFD);
            PublicMethod.ClearDataGridViewData(dgvArgument);
            PublicMethod.ClearDataGridViewData(dgvArgumentType);
            PublicMethod.ClearDataGridViewData(dgvDataReturn);
            PublicMethod.ClearDataGridViewData(dgvYaoSu);
            //chromiumWebBrowser1.Load("http://www.163.com");
        }

        /// <summary>
        /// 删除节点关系配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDele_Click(object sender, EventArgs e)
        {
            if (dgvYaoSu.Rows.Count > 0)
            {
                if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    #region MyRegion
                    //if (dgvYaoSu.Rows[0].Cells["IsPublic"].Value.ToString() == "是")
                    //{
                    //    if (!string.IsNullOrEmpty(extractFeature.EF_ID) && !string.IsNullOrEmpty(extractInfo.EXI_ID))
                    //    {
                    //        //删除表ExtractFeature
                    //        extractFeatureBll.ExtractFeatureDelete(extractFeature.EF_ID);
                    //        //删除表ExtractInfo
                    //        extractFeatureBll.ExtractInfoDelete(extractInfo.EXI_ID);
                    //        MessageBox.Show("删除成功！");
                    //        PublicMethod.ClearDataGridViewData(dgvYS);
                    //        PublicMethod.ClearDataGridViewData(dgvFD);
                    //        PublicMethod.ClearDataGridViewData(dgvArgument);
                    //        PublicMethod.ClearDataGridViewData(dgvArgumentType);
                    //        PublicMethod.ClearDataGridViewData(dgvHanShu);
                    //        PublicMethod.ClearDataGridViewData(dgvDataReturn);
                    //        PublicMethod.ClearDataGridViewData(dgvYaoSu);
                    //        return;
                    //    }
                    //}
                    //else if (dgvYaoSu.Rows[0].Cells["IsPublic"].Value.ToString() == "否")
                    //{ 
                    #endregion

                    if (IsXinZeng)
                    {
                        rm = new ReturnMode();
                        ees = new ElementExtractSource();
                        cm = new ConvertMode();

                        extractInfo = new ExtractInfo();
                        PublicMethod.ClearDataGridViewData(dgvYS);
                        PublicMethod.ClearDataGridViewData(dgvFD);
                        PublicMethod.ClearDataGridViewData(dgvArgument);
                        PublicMethod.ClearDataGridViewData(dgvHanShu);
                        PublicMethod.ClearDataGridViewData(dgvArgumentType);
                        PublicMethod.ClearDataGridViewData(dgvDataReturn);
                        PublicMethod.ClearDataGridViewData(dgvYaoSu);
                        //chromiumWebBrowser1.Load("about:blank");
                        if (!string.IsNullOrEmpty(extractFeature.RIU_ID))
                        {
                            string url = string.Format(urlNew + "InformationUnit/InUn_MainList?riu_id={0}&userid={1}&state=del ", extractFeature.RIU_ID, Gvar.uo.m_userId);
                            webBrowerUser1.LoadUrl(url);

                            //webBrowser1.Url = new Uri(url);
                            //webBrowser1.ObjectForScripting = this;
                            //webBrowser1.DocumentText = "";
                        }
                        extractFeature = new ExtractFeature();
                    }
                    else if (!string.IsNullOrEmpty(extractFeature.EF_ID))
                    {
                        if (GetYYLiuCheng())
                        {
                            //删除表ExtractFeature
                            extractFeatureBll.ExtractFeatureDelete(extractFeature.EF_ID);
                            //删除表ExtractInfo
                            //extractFeatureBll.ExtractInfoDelete(extractInfo.EXI_ID);
                            //删除表ReturnMode
                            //returnModelBll.ReturnModeDelete(extractFeature.RM_ID);
                            ////删除表ConvertMode
                            //convertModelBll.ConvertModeDelete(extractFeature.CM_ID);

                            //RuleInfosDelete(extractFeature.RIU_ID);
                            MessageBox.Show("删除成功！");
                            PublicMethod.ClearDataGridViewData(dgvYS);
                            PublicMethod.ClearDataGridViewData(dgvFD);
                            PublicMethod.ClearDataGridViewData(dgvArgument);
                            PublicMethod.ClearDataGridViewData(dgvArgumentType);
                            PublicMethod.ClearDataGridViewData(dgvDataReturn);
                            PublicMethod.ClearDataGridViewData(dgvYaoSu);
                            //webBrowerUser1.LoadUrl("about:blank");
                            return;
                        }
                    }
                    // }
                }
            }
            else
            {
                MessageBox.Show("没有需要删除的数据");
                return;
            }
        }

        public void RuleInfosDelete(string riuId)
        {
            DataTable dt = ruleInfoBll.RuleInfoParmeterRelationData(riuId);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (Convert.ToInt32(ruleInfoBll.GetPLIDCount(riuId, dr["PL_ID"].ToString())) > 0)
                    {
                        ruleInfoBll.RuleInfoParmeterRelationDelete(riuId, dr["PL_ID"].ToString());
                    }
                    else if (string.IsNullOrEmpty(ruleInfoBll.GetPLIDCount(riuId, dr["PL_ID"].ToString())))
                    {

                        ruleInfoBll.Riu_ParameterDelete(riuId, dr["PL_ID"].ToString());
                    }
                }
            }
            dt = ruleInfoBll.Riu_RuleRelationData(riuId);
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    DataTable dtNew = ruleInfoBll.RR_RelationTable_IDNum(riuId, dr["RR_RelationTable_ID"].ToString());
                    if (dtNew != null && dtNew.Rows.Count == 1)
                    {
                        ruleInfoBll.Riu_ParameterDelete(dr["RR_RelationTable_ID"].ToString(), Convert.ToInt32(dtNew.Rows[0][0]));
                    }
                    else if (dtNew != null && dtNew.Rows.Count == 0)
                    {
                        ruleInfoBll.Riu_RuleRelationDelete(riuId, dr["RR_RelationTable_ID"].ToString());
                    }
                }
            }
            ruleInfoBll.RuleInfoUnitDelete(riuId);
        }
        //returnModelBll = new ReturnModeBLL();
        //ConvertModeBLL convertModelBll = new ConvertModeBLL();
        //SYS_ArgumentBLL sysArgumentBll



        /// <summary>
        /// 添加数据返回方式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDataReturnAdd_Click(object sender, EventArgs e)
        {
            if (dgvDataReturn.Rows.Count == 0 && dgvYaoSu.Rows.Count > 0)
            {
                if (GetYYLiuCheng())
                {
                    DataReturnConfig dc = new DataReturnConfig();
                    dc.state = "添加";
                    dc.rm = new ReturnMode();
                    dc.IsAdd = IsXinZeng;
                    dc.rm.RM_ID = extractFeature.RM_ID;
                    var dialogResult = dc.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {

                        DataTable dt = new DataTable();
                        dt.Columns.AddRange(new DataColumn[] { new DataColumn("RM_Code"), new DataColumn("RM_CodeZH"), new DataColumn("RM_IsValue"), new DataColumn("RM_JoinMode"), new DataColumn("RM_ID") });
                        DataRow dr = dt.NewRow();
                        dr["RM_Code"] = dc.rm.RM_Code;
                        dr["RM_CodeZH"] = dc.rm.RM_CodeZH;
                        dr["RM_IsValue"] = dc.rm.RM_IsValue == 0 ? "是" : "否";
                        dr["RM_JoinMode"] = dc.rm.RM_JoinMode;
                        dr["RM_ID"] = dc.rm.RM_ID;
                        dt.Rows.Add(dr);
                        dgvDataReturn.DataSource = dt;
                        rm = dc.rm;
                        extractFeature.RM_ID = rm.RM_ID;

                    }
                    else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(dc.rm.RM_Code))
                    {
                        MessageBox.Show("请将数据返回方式配置完整！");
                        return;
                    }
                }
            }
            else if (dgvDataReturn.Rows.Count > 0)
            {
                MessageBox.Show("请选择列表中的数据进行修改或者删除后进行添加！");
                return;
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 删除数据返回方式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDataReturnDel_Click(object sender, EventArgs e)
        {
            if (dgvYaoSu.Rows.Count == 0)
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
            if (dgvDataReturn.Rows.Count == 1)
            {

                if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (IsXinZeng)
                    {
                        PublicMethod.ClearDataGridViewData(dgvDataReturn);
                        extractFeature.RM_ID = "";
                    }
                    else if (dgvDataReturn.Rows[0].Cells["RM_ID"].Value != null && !string.IsNullOrEmpty(dgvDataReturn.Rows[0].Cells["RM_ID"].Value.ToString()))
                    {
                        if (GetYYLiuCheng())
                        {
                            string rmID = dgvDataReturn.Rows[0].Cells["RM_ID"].Value.ToString();
                            if (returnModelBll.ReturnModeDelete(rmID))
                            {
                                MessageBox.Show("删除成功！");
                                PublicMethod.ClearDataGridViewData(dgvDataReturn);
                                extractFeature.RM_ID = "";
                            }
                            else
                            {
                                MessageBox.Show("删除失败！");
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("没有需要删除的数据！");
                return;
            }

        }

        /// <summary>
        /// 修改数据返回方式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDataReturnUpdate_Click(object sender, EventArgs e)
        {
            if (dgvDataReturn.Rows.Count > 0)
            {
                if (GetYYLiuCheng())
                {
                    DataReturnConfig dc = new DataReturnConfig();
                    if (dgvDataReturn.Rows[0].Cells["RM_ID"].Value != null && !string.IsNullOrEmpty(dgvDataReturn.Rows[0].Cells["RM_ID"].Value.ToString()))
                    {
                        dc.rm.RM_ID = dgvDataReturn.Rows[0].Cells["RM_ID"].Value.ToString();
                    }
                    dc.state = "修改";
                    dc.IsAdd = IsXinZeng;
                    dc.rm.RM_Code = dgvDataReturn.Rows[0].Cells["RM_Code"].Value.ToString();
                    dc.rm.RM_CodeZH = dgvDataReturn.Rows[0].Cells["RM_CodeZH"].Value.ToString();
                    dc.rm.RM_IsValue = Convert.ToInt32(dgvDataReturn.Rows[0].Cells["RM_IsValue"].Value.ToString() == "是" ? 0 : 1);
                    dc.rm.RM_JoinMode = dgvDataReturn.Rows[0].Cells["RM_JoinMode"].Value.ToString();
                    var dialogResult = dc.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {
                        PublicMethod.ClearDataGridViewData(dgvDataReturn);
                        rm = dc.rm;
                        DataTable dt = new DataTable();
                        dt.Columns.AddRange(new DataColumn[] { new DataColumn("RM_Code"), new DataColumn("RM_CodeZH"), new DataColumn("RM_IsValue"), new DataColumn("RM_JoinMode"), new DataColumn("RM_ID") });
                        DataRow dr = dt.NewRow();
                        dr["RM_Code"] = dc.rm.RM_Code;
                        dr["RM_CodeZH"] = dc.rm.RM_CodeZH;
                        dr["RM_IsValue"] = dc.rm.RM_IsValue == 0 ? "是" : "否";
                        dr["RM_JoinMode"] = dc.rm.RM_JoinMode;
                        dr["RM_ID"] = dc.rm.RM_ID;
                        dt.Rows.Add(dr);
                        dgvDataReturn.DataSource = dt;

                    }
                    else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(dc.rm.RM_Code))
                    {
                        MessageBox.Show("请将数据返回方式配置完整！");
                        return;
                    }
                }
            }
            else if (dgvYaoSu.Rows.Count == 0)
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 对字符串进行Base64编码  
        /// </summary>
        /// <param name="codepage"></param>
        /// <param name="decode"></param>
        /// <returns></returns>
        public static string EnCodeBase64(string decode)
        {
            string encode = "";
            try
            {
                byte[] bytes = Encoding.GetEncoding(65001).GetBytes(decode);
                encode = Convert.ToBase64String(bytes);
            }
            catch
            {
                encode = "";
            }
            return encode;
        }

        /// <summary>
        /// 要素内容点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvYaoSu_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //webBrowerUser1.Load("http://www.baidu.com");

            //于2020年4月14日提出不允许在根节点进行配置规则。
            if (tabControlModule.SelectedTab.Text == "逻辑分段" && clicknode.Parent == null)
            {
                return;
            }
            if (dgvYaoSu.Rows.Count == 1)
            {
                var RIU_ID = extractFeature.RIU_ID;
                if (!string.IsNullOrEmpty(RIU_ID))//修改
                {
                   // chromiumWebBrowser1 = new CefSharp.WinForms.ChromiumWebBrowser("www.baidu.com");
                    Random rd = new Random();
                    Uri url =new Uri(urlNew + $"InformationUnit/InUn_MainList?riu_id={RIU_ID}&userid={Gvar.uo.m_userId}&ElemType=1&a={rd.Next(10000, 20000).ToString()}");
                    //chromiumWebBrowser1.Load("");
                    //Thread.Sleep(500);
                    if (Uri.IsWellFormedUriString(url.ToString(), UriKind.RelativeOrAbsolute))
                    {
                        webBrowerUser1.LoadUrl(url.ToString());
                        //chromiumWebBrowser1.Load(url.ToString());
                    }
                    //Thread.Sleep(500);
                    //tabControlConfig.SelectedIndex = 0;
                    //Thread.Sleep(500);
                    //tabControlConfig.SelectedIndex = 1;
                    //LoadElementExtractSourceData();
                    //dgvYaoSu_CellContentClick(null, null);
                    //chromiumWebBrowser1.Load(url.ToString());                                       
                    //webBrowser1.Url = new Uri(url);
                    //webBrowser1.ObjectForScripting = this;//2、设置js中window.external对象代表的类  
                }
                else
                {//添加
                 //clicknode.FullPath
                    string tabName = tabControlModule.SelectedTab.Text;
                    string url = string.Empty;
                    if (tabName == "逻辑分段")
                    {
                        url = string.Format(urlNew + "InformationUnit/InUn_MainList?riu_id={0}&userid={1}&Code={2}&CodeCH={3}&ElemType=1 ", "", Gvar.uo.m_userId, clicknode.Tag.ToString().Split('!')[0].ToString().Trim(), EnCodeBase64(EnCodeBase64(clicknode.Text.ToString().Trim())));
                    }
                    else if (tabName == "案件要素中心")
                    {
                        string st1 = string.Empty;
                        if (dicc.ContainsKey("\"\\" + clicknode.FullPath + "\""))
                        {
                            st1 = dicc["\"\\" + clicknode.FullPath + "\""].Replace("\"", "");
                        }
                        // cbTreeViewDocType.TreeView.SelectedNode.Tag.ToString()
                        url = string.Format(urlNew + "InformationUnit/InUn_MainList?riu_id={0}&userid={1}&Code={2}&CodeCH={3}&ElemType=1", "", Gvar.uo.m_userId, st1 + "$" + cbTreeViewDocType.TreeView.SelectedNode.Tag.ToString().Trim(), EnCodeBase64(EnCodeBase64(clicknode.Text.ToString().Trim())));

                    }
                    webBrowerUser1.LoadUrl(url);
                    //webBrowser1.Url = new Uri(url);
                    //webBrowser1.ObjectForScripting = this;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }


        /// <summary>
        /// 接收信息单元数据
        /// </summary>
        /// <param name="RIU_ID"></param>
        public void ShowMessage(object ct, string RIU_ID)
        {
            if (!string.IsNullOrEmpty(RIU_ID))
            {
                extractFeature.RIU_ID = RIU_ID;
                //dgvYaoSu.Rows[0].Cells["RIU_ID"].Value = RIU_ID;
                string url = string.Format(urlNew + "InformationUnit/InUn_MainList?riu_id={0}&userid={1}&ElemType=1 ", RIU_ID, Gvar.uo.m_userId);
                webBrowerUser1.LoadUrl(url);
                //webBrowser1.Url = new Uri(url);
                //webBrowser1.ObjectForScripting = this;
            }
        }

        /// <summary>
        /// 转换方式选择
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbxConvertMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            //0案件字典1案由字典2函数
            if (cbxConvertMode.SelectedIndex == 0 || cbxConvertMode.SelectedIndex == 1)
            {
                panelDictionary.Visible = true;
                panelDictionary.Dock = DockStyle.Fill;
                panelHanSu.Dock = DockStyle.None;
                panelHanSu.Visible = false;
                loadDictionary();
            }
            else if (cbxConvertMode.SelectedIndex == 2)
            {
                panelHanSu.Visible = true;
                panelHanSu.Dock = DockStyle.Fill;
                panelDictionary.Dock = DockStyle.None;
                panelDictionary.Visible = false;
                loadHanShu();
            }
        }

        /// <summary>
        /// 加载函数
        /// </summary>
        private void loadHanShu()
        {
            if (!string.IsNullOrEmpty(extractFeature.CM_ID))
            {
                DataTable dtSelect = convertModelBll.GetConvertModeData(extractFeature.CM_ID);
                if (dtSelect != null && dtSelect.Rows.Count > 0)
                {
                    if (dtSelect.Rows[0]["CM_CMode"].ToString() == "0" || dtSelect.Rows[0]["CM_CMode"].ToString() == "3")
                    {
                        JZData();
                    }
                    else if (dtSelect.Rows[0]["CM_CMode"].ToString() == "1" || dtSelect.Rows[0]["CM_CMode"].ToString() == "2")
                    {

                    }
                }
                DataTable dt = convertModelBll.GetConvertModeHanShuData(extractFeature.CM_ID);
                //if (dt.Rows.Count > 0 && dt.Select(" CM_CMode<>0 ").Length > 0)
                //{
                //    dt = dt.Select("CM_CMode<>0 ").CopyToDataTable();
                //}
                //else
                //{
                //    dt = new DataTable();
                //}
                DataTable showdt = new DataTable();
                showdt.Columns.AddRange(new DataColumn[] { new DataColumn("HanShuName"), new DataColumn("HanShuParameter"), new DataColumn("CM_ID"), new DataColumn("CM_Custom"), new DataColumn("CM_MethodParameter"), new DataColumn("CM_Method") });
                if (dt != null && dt.Rows.Count > 0)
                {
                    string cm_Method = dt.Rows[0]["CM_Method"].ToString();
                    string cm_ID = dt.Rows[0]["CM_ID"].ToString();
                    string cm_Parameter = dt.Rows[0]["CM_MethodParameter"].ToString();
                    DataRow dr = showdt.NewRow();
                    dr["HanShuName"] = dicYaoSu.ContainsKey(cm_Method) ? dicYaoSu[cm_Method].Split(',')[0].ToString() : cm_Method;
                    if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm_Method))
                    {
                        List<parameters> formats = dicYaoSuParams[cm_Method];
                        if (formats.Count > 0)
                        {
                            foreach (parameters item in formats)
                            {
                                if (item.name == cm_Parameter)
                                {
                                    dr["HanShuParameter"] = item.remark;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        dr["HanShuParameter"] = "";
                    }
                    dr["CM_ID"] = cm_ID;
                    dr["CM_Custom"] = dt.Rows[0]["CM_Custom"].ToString();
                    dr["CM_MethodParameter"] = cm_Parameter;
                    dr["CM_Method"] = cm_Method;
                    showdt.Rows.Add(dr);
                    //CM_ID,CM_Method,CM_UpdateTime,CM_CMode,CM_MethodParameter,CM_Custom,CM_Code,CM_CodeCH
                    cm = new ConvertMode()
                    {
                        CM_ID = dt.Rows[0]["CM_ID"].ToString(),
                        CM_Code = dt.Rows[0]["CM_Code"].ToString(),
                        CM_CodeCH = dt.Rows[0]["CM_CodeCH"].ToString(),
                        CM_CMode = Convert.ToInt32(dt.Rows[0]["CM_CMode"].ToString()),
                        CM_Method = dt.Rows[0]["CM_Method"].ToString(),
                        CM_MethodParameter = dt.Rows[0]["CM_MethodParameter"].ToString(),
                        CM_UpdateTime = DateTime.Now
                    };
                    dgvHanShu.DataSource = showdt;
                }
                else
                {
                    DataTable dt1 = (DataTable)dgvHanShu.DataSource;
                    if (dt1 != null)
                    { dt1.Rows.Clear(); }
                    dgvHanShu.DataSource = dt1;
                }
            }
            else
            {
                //案件要素中心下有字典值的进行展示
                if (tabControlModule.SelectedTab.Text == "案件要素中心")
                {
                    string xmlPath = clicknode.FullPath;
                    string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                    caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                    DataTable dt1 = convertModelBll.GetConvertMode(xmlPath, caseType);
                    if (dt1 != null && dt1.Rows.Count > 0)
                    {
                        extractFeature.CM_ID = dt1.Rows[0]["CM_ID"].ToString();
                        ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                        efBll.ExtractFeatureUpdateCMID(ef);
                        //0关联案件字典 1函数 2函数sql 3关联案由字典
                        if (dt1.Rows[0]["CM_CMode"].ToString() == "0")
                        {
                            cbxConvertMode.SelectedIndex = 0;
                            loadDictionary();
                        }
                        else if (dt1.Rows[0]["CM_CMode"].ToString() == "3")
                        {
                            cbxConvertMode.SelectedIndex = 1;
                        }
                        else if (dt1.Rows[0]["CM_CMode"].ToString() == "1" || dt1.Rows[0]["CM_CMode"].ToString() == "2")
                        {
                            cbxConvertMode.SelectedIndex = 2;
                        }

                    }
                    else
                    {
                        DataTable dt2 = (DataTable)dgvHanShu.DataSource;
                        if (dt2 != null)
                        { dt2.Rows.Clear(); }
                        dgvHanShu.DataSource = dt2;
                    }
                }
                else
                {
                    DataTable dt1 = (DataTable)dgvHanShu.DataSource;
                    if (dt1 != null)
                    { dt1.Rows.Clear(); }
                    dgvHanShu.DataSource = dt1;
                }
            }
        }


        /// <summary>
        /// 加载字典值
        /// </summary>
        private void loadDictionary()
        {
            if (dgvYaoSu.Rows.Count == 1)
            {
                if (cbxConvertMode.SelectedIndex == 0)
                {
                    dgvArgumentType.Columns["AR_CauseCode1"].Visible = false;
                }
                else if (cbxConvertMode.SelectedIndex == 1)
                {
                    dgvArgumentType.Columns["AR_CauseCode1"].Visible = true;
                }
                //cm_id不为空
                if (!string.IsNullOrEmpty(extractFeature.CM_ID))
                {
                    panelDictionary.Visible = true;
                    panelDictionary.Dock = DockStyle.Fill;
                    panelHanSu.Dock = DockStyle.None;
                    panelHanSu.Visible = false;
                    DataTable dt = convertModelBll.GetConvertModeData(extractFeature.CM_ID);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        if (dt.Rows[0]["CM_CMode"].ToString() == "0" || dt.Rows[0]["CM_CMode"].ToString() == "3")
                        {
                            JZData();
                        }
                        else if (dt.Rows[0]["CM_CMode"].ToString() == "1" || dt.Rows[0]["CM_CMode"].ToString() == "2")
                        {
                            cbxConvertMode.SelectedIndex = 2;
                        }
                    }
                    else
                    {
                        if (tabControlModule.SelectedTab.Text == "案件要素中心")
                        {
                            string xmlPath = clicknode.FullPath;
                            string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                            caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                            DataTable dt1 = convertModelBll.GetConvertMode(xmlPath, caseType);
                            if (dt1 != null && dt1.Rows.Count > 0)
                            {
                                extractFeature.CM_ID = dt1.Rows[0]["CM_ID"].ToString();
                                ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                                efBll.ExtractFeatureUpdateCMID(ef);

                                //0关联案件字典 1函数 2函数sql 3关联案由字典
                                if (dt1.Rows[0]["CM_CMode"].ToString() == "0")
                                {
                                    cbxConvertMode.SelectedIndex = 0;
                                    loadDictionary();
                                }
                                else if (dt1.Rows[0]["CM_CMode"].ToString() == "3")
                                {
                                    cbxConvertMode.SelectedIndex = 1;
                                }
                                else if (dt1.Rows[0]["CM_CMode"].ToString() == "1" || dt1.Rows[0]["CM_CMode"].ToString() == "2")
                                {
                                    cbxConvertMode.SelectedIndex = 2;
                                }
                            }
                        }

                        #region 原有代码
                        //    if (tabControlModule.SelectedTab.Text == "案件要素中心")
                        //{
                        //    string xmlPath = clicknode.FullPath;
                        //    string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                        //    caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                        //    DataTable dt1 = convertModelBll.GetConvertModeData(xmlPath, caseType);
                        //    if (dt1 != null && dt1.Rows.Count > 0)
                        //    {
                        //        if (dt1.Select("CM_CMode=0").Length == 1)
                        //        {
                        //            DataRow dr1 = dt1.Select("CM_CMode=0")[0];
                        //            extractFeature.CM_ID = dr1["CM_ID"].ToString();
                        //            cbxConvertMode.SelectedIndex = 0;
                        //            ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                        //            efBll.ExtractFeatureUpdateCMID(ef);
                        //            loadDictionary();

                        //        }
                        //        else if (dt1.Select("CM_CMode<>0 ").Length == 1)
                        //        {
                        //            DataRow dr1 = dt1.Select("CM_CMode<>0 ")[0];
                        //            extractFeature.CM_ID = dr1["CM_ID"].ToString();
                        //            ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                        //            efBll.ExtractFeatureUpdateCMID(ef);
                        //            cbxConvertMode.SelectedIndex = 1;
                        //            //loadHanShu();
                        //        }
                        //    }
                        //} 
                        #endregion
                    }
                }
                else
                {
                    //案件要素中心下有字典值的进行展示
                    if (tabControlModule.SelectedTab.Text == "案件要素中心")
                    {
                        string xmlPath = clicknode.FullPath;
                        string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                        caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                        DataTable dt1 = convertModelBll.GetConvertMode(xmlPath, caseType);
                        if (dt1 != null && dt1.Rows.Count > 0)
                        {
                            extractFeature.CM_ID = dt1.Rows[0]["CM_ID"].ToString();
                            ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                            efBll.ExtractFeatureUpdateCMID(ef);
                            //0关联案件字典 1函数 2函数sql 3关联案由字典
                            if (dt1.Rows[0]["CM_CMode"].ToString() == "0")
                            {
                                cbxConvertMode.SelectedIndex = 0;
                                loadDictionary();
                            }
                            else if (dt1.Rows[0]["CM_CMode"].ToString() == "3")
                            {
                                cbxConvertMode.SelectedIndex = 1;
                            }
                            else if (dt1.Rows[0]["CM_CMode"].ToString() == "1" || dt1.Rows[0]["CM_CMode"].ToString() == "2")
                            {
                                cbxConvertMode.SelectedIndex = 2;
                            }

                            #region 原有代码
                            //if (dt1.Select("CM_CMode=0").Length == 1)
                            //{
                            //    DataRow dr1 = dt1.Select("CM_CMode=0")[0];

                            //    cbxConvertMode.SelectedIndex = 0;
                            //    //ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                            //    //efBll.ExtractFeatureUpdateCMID(ef);
                            //    loadDictionary();

                            //}
                            //else if (dt1.Select("CM_CMode<>0 ").Length == 1)
                            //{
                            //    DataRow dr1 = dt1.Select("CM_CMode<>0 ")[0];
                            //    extractFeature.CM_ID = dr1["CM_ID"].ToString();
                            //    cbxConvertMode.SelectedIndex = 1;
                            //    //ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                            //    //efBll.ExtractFeatureUpdateCMID(ef);
                            //    //loadHanShu();

                            //} 
                            #endregion
                        }


                    }
                }
            }

        }

        /// <summary>
        /// 加载字典值数据
        /// </summary>
        public void JZData()
        {
            DataTable dt = convertModelBll.GetConvertModeDataNew(extractFeature.CM_ID);
            if (dt != null && dt.Rows.Count > 0)
            {
                string cm_CMode = dt.Rows[0]["CM_CMode"].ToString();
                if (!string.IsNullOrEmpty(cm_CMode))
                {
                    if (cm_CMode == "0")
                    {
                        dgvArgumentType.Columns["AR_CauseCode1"].Visible = false;
                        cbxConvertMode.SelectedIndex = 0;
                    }
                    else if (cm_CMode == "3")
                    {
                        dgvArgumentType.Columns["AR_CauseCode1"].Visible = true;
                        cbxConvertMode.SelectedIndex = 1;
                    }


                    DataTable showdt = new DataTable();
                    showdt.Columns.AddRange(new DataColumn[] { new DataColumn("CM_Code"), new DataColumn("CM_CodeCH"), new DataColumn("AT_Code"), new DataColumn("AT_Name"), new DataColumn("AT_WordsMode"), new DataColumn("CM_ID"), new DataColumn("AT_ID"), new DataColumn("CM_Custom"), new DataColumn("AR_CauseCode1"), new DataColumn("AR_ID1") });


                    foreach (DataRow dr in dt.Rows)
                    {
                        DataRow dr1 = showdt.NewRow();
                        dr1["CM_Code"] = dr["CM_Code"];
                        dr1["CM_CodeCH"] = dr["CM_CodeCH"];
                        dr1["AT_Code"] = dr["AT_Code"];
                        dr1["AT_Name"] = sysArgumentTypeData.Select("AT_ID='" + dr["AT_ID"] + "'")[0]["AT_Name"].ToString();
                        dr1["AT_WordsMode"] = sysArgumentTypeData.Select("AT_ID='" + dr["AT_ID"] + "'")[0]["AT_WordsMode"].ToString();
                        dr1["AT_ID"] = dr["AT_ID"].ToString();
                        dr1["CM_ID"] = dr["CM_ID"];
                        dr1["CM_Custom"] = dr["CM_Custom"];
                        dr1["AR_CauseCode1"] = string.IsNullOrEmpty(dr["AR_CauseCode"].ToString()) ? "" : sysCaseCauseTable.Select(" ID='" + dr["AR_CauseCode"].ToString() + "'")[0]["Name"].ToString();
                        dr1["AR_ID1"] = dr["AR_ID"];
                        showdt.Rows.Add(dr1);
                    }
                    dgvArgumentType.DataSource = showdt;
                    cm = new ConvertMode()
                    {
                        CM_ID = dt.Rows[0]["CM_ID"].ToString(),
                        CM_Code = dt.Rows[0]["CM_Code"].ToString(),
                        CM_CodeCH = dt.Rows[0]["CM_CodeCH"].ToString(),
                        CM_CMode = Convert.ToInt32(dt.Rows[0]["CM_CMode"].ToString()),
                        AT_ID = dt.Rows[0]["AT_ID"].ToString(),
                        AT_Code = dt.Rows[0]["AT_Code"].ToString()
                    };
                    dgvArgument.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(cm.AT_ID);
                    //extractFeature.CM_ID = cm.CM_ID;
                    //cbxConvertMode.Text = "字典值";

                }
            }
        }


        /// <summary>
        /// 获取数据返回方式数据
        /// </summary>
        private void LoadReturnModeData()
        {
            //if (!IsXinZeng)
            //{
            if (!string.IsNullOrEmpty(extractFeature.RM_ID))
            {
                DataTable dt = returnModelBll.GetReturnModeData(extractFeature.RM_ID);
                if (dt != null && dt.Rows.Count > 0)
                {
                    DataTable dt1 = new DataTable();
                    dt1.Columns.AddRange(new DataColumn[] { new DataColumn("RM_Code"), new DataColumn("RM_CodeZH"), new DataColumn("RM_IsValue"), new DataColumn("RM_JoinMode"), new DataColumn("RM_ID") });
                    DataRow dr = dt1.NewRow();
                    dr["RM_Code"] = dt.Rows[0]["RM_Code"].ToString();
                    dr["RM_CodeZH"] = dt.Rows[0]["RM_CodeZH"].ToString();
                    dr["RM_IsValue"] = Convert.ToInt32(dt.Rows[0]["RM_IsValue"].ToString()) == 0 ? "是" : "否";
                    dr["RM_JoinMode"] = dt.Rows[0]["RM_JoinMode"].ToString();
                    dr["RM_ID"] = dt.Rows[0]["RM_ID"].ToString();
                    dt1.Rows.Add(dr);
                    dgvDataReturn.DataSource = dt1;
                    rm = new ReturnMode()
                    {
                        RM_ID = dt.Rows[0]["RM_ID"].ToString(),
                        RM_Code = dt.Rows[0]["RM_Code"].ToString(),
                        RM_CodeZH = dt.Rows[0]["RM_CodeZH"].ToString(),
                        RM_IsValue = Convert.ToInt32(dt.Rows[0]["RM_IsValue"].ToString()),
                        RM_JoinMode = dt.Rows[0]["RM_JoinMode"].ToString()
                    };

                }
            }
            // }

        }

        /// <summary>
        /// 加载规则配置
        /// </summary>
        private void LoadElementExtractSourceData()
        {
            //字段选择
            if (tabControlModule.SelectedIndex == 0 && dgvYaoSu.Rows.Count == 1 && !string.IsNullOrEmpty(extractFeature.EES_ID))
            {
                DataTable dt1 = elementExtractSourceBll.GetElementExtractSourceData(extractFeature.EES_ID);
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[] { new DataColumn("FdRuleNum"), new DataColumn("FdCodeCH"), new DataColumn("FdSourceName"), new DataColumn("FdPargraphName"), new DataColumn("FdIsQuanWen"), new DataColumn("FdWhere"), new DataColumn("EES_ID"), new DataColumn("IsML1") });
                    DataRow dr = dt.NewRow();
                    dr["FdRuleNum"] = "1";
                    dr["FdCodeCH"] = dt1.Rows[0]["EES_CodeCH"].ToString();
                    dr["FdSourceName"] = cbTreeViewDocType.Text;
                    dr["FdIsQuanWen"] = Convert.ToInt32(dt1.Rows[0]["EES_SourceType"].ToString()) == 4 ? "是" : "否";
                    dr["FdWhere"] = dt1.Rows[0]["EES_Where"].ToString();
                    dr["EES_ID"] = extractFeature.EES_ID;
                    dr["FdPargraphName"] = dt1.Rows[0]["EES_ParagraphName"].ToString(); ;
                    dr["IsML1"] = dt1.Rows[0]["IsML"] == null ? "否" : dt1.Rows[0]["IsML"].ToString() == "1" ? "是" : "否";
                    dt.Rows.Add(dr);
                    dgvFD.DataSource = dt;
                    ees.EES_ID = extractFeature.EES_ID;
                    ees.EES_Code = dt1.Rows[0]["EES_Code"].ToString();
                    ees.EES_CodeCH = Convert.ToString(dr["FdCodeCH"]);
                    ees.EES_SourceName = cbTreeViewDocType.Text;
                    ees.EES_SourceType = Convert.ToInt32(dt1.Rows[0]["EES_SourceType"].ToString());
                    ees.EES_ElementType = Convert.ToInt32(dt1.Rows[0]["EES_ElementType"].ToString());
                    ees.EES_Where = dt1.Rows[0]["EES_Where"].ToString();
                    ees.EES_Remark = dt1.Rows[0]["EES_Remark"].ToString();
                }

            }//要素中心选择
            else if (tabControlModule.SelectedIndex == 1 && dgvYaoSu.Rows.Count == 1 && !string.IsNullOrEmpty(extractFeature.EES_ID))
            {

                DataTable dt1 = elementExtractSourceBll.GetElementExtractSourceData(extractFeature.EES_ID);
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    DataTable dt = new DataTable();
                    dt.Columns.AddRange(new DataColumn[] { new DataColumn("YSRuleNum"), new DataColumn("YSCodeCH"), new DataColumn("YSSourceName"), new DataColumn("YSIsQuanWen"),
                            new DataColumn("YSIsYuanWen"), new DataColumn("YSIsLuJiDuan"), new DataColumn("YSIsLuJiDuanType"),
                        new DataColumn("YSIsLuJiDuanCode"), new DataColumn("YsName"), new DataColumn("YsWhere"), new DataColumn("EES_ID1"), new DataColumn("IsML")});
                    DataRow dr = dt.NewRow();
                    dr["YSRuleNum"] = "1";
                    dr["YSCodeCH"] = dt1.Rows[0]["EES_CodeCH"].ToString();
                    dr["YSSourceName"] = dt1.Rows[0]["EES_SourceName"].ToString();
                    switch (Convert.ToInt32(dt1.Rows[0]["EES_SourceType"].ToString()))
                    {
                        case 4:
                            dr["YSIsQuanWen"] = "是";
                            break;
                        case 3:
                            dr["YSIsYuanWen"] = "是";
                            break;
                        case 1:
                            dr["YSIsLuJiDuan"] = "是";
                            dr["YSIsLuJiDuanType"] = "对话逻辑段";
                            dr["YSIsLuJiDuanCode"] = dt1.Rows[0]["EES_ParagraphName"].ToString();
                            break;
                        case 2:
                            dr["YSIsLuJiDuan"] = "是";
                            dr["YSIsLuJiDuanType"] = "逻辑段原文";
                            dr["YSIsLuJiDuanCode"] = dt1.Rows[0]["EES_ParagraphName"].ToString();
                            break;
                    }
                    dr["YsName"] = dt1.Rows[0]["EES_ElementPath"].ToString();
                    dr["YsWhere"] = dt1.Rows[0]["EES_Where"].ToString();
                    dr["EES_ID1"] = extractFeature.EES_ID;
                    dr["IsML"] = dt1.Rows[0]["IsML"] == null ? "否" : dt1.Rows[0]["IsML"].ToString() == "1" ? "是" : "否";
                    dt.Rows.Add(dr);
                    dgvYS.DataSource = dt;
                    ees.EES_ID = extractFeature.EES_ID;
                    ees.EES_Code = dt1.Rows[0]["EES_Code"].ToString();
                    ees.EES_CodeCH = Convert.ToString(dr["YSCodeCH"]);
                    ees.EES_SourceName = cbTreeViewDocType.Text;
                    ees.EES_SourceType = Convert.ToInt32(dt1.Rows[0]["EES_SourceType"].ToString());
                    ees.EES_ElementType = Convert.ToInt32(dt1.Rows[0]["EES_ElementType"].ToString());
                    ees.EES_ElementPath = dt1.Rows[0]["EES_ElementPath"].ToString();
                    ees.EES_Where = dt1.Rows[0]["EES_Where"].ToString();
                    ees.EES_Remark = dt1.Rows[0]["EES_Remark"].ToString();
                }
            }
        }


        /// <summary>
        /// 关系配置切页查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabControlConfig_SelectedIndexChanged(object sender, EventArgs e)
        {
           // chromiumWebBrowser1.Load("http://www.baidu.com");
            if (dgvYaoSu.Rows.Count == 1 && !string.IsNullOrEmpty(extractInfo.EXI_ID))
            {
                switch (tabControlConfig.SelectedTab.Text)
                {
                    case "规则配置":
                        LoadElementExtractSourceData();
                        break;
                    case "规则提取":
                        dgvYaoSu_CellContentClick(null, null);
                        break;
                    case "属性配置":
                        cbxConvertMode.SelectedIndex = 0;
                        cbxConvertMode_SelectedIndexChanged(null, null);
                        break;
                    case "数据返回方式":
                        LoadReturnModeData();
                        break;
                }
            }
            else if (dgvYaoSu.Rows.Count == 0)
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 规则添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRuleAdd_Click(object sender, EventArgs e)
        {
            //字段选择
            if (tabControlModule.SelectedIndex == 0 && dgvYaoSu.Rows.Count == 1)
            {
                if (dgvFD.Rows.Count == 0)
                {
                    if (GetYYLiuCheng())
                    {
                        config cf = new config() { bookName = cbTreeViewDocType.Text };
                        RuleConfig rc = new RuleConfig(cf, 0, 0);
                        if (clicknode.FullPath.Replace("\\", @"\").Split(new char[] { '\\' }).Length > 2)
                        {
                            rc.IsCanChecked = true;
                        }
                        else
                        {
                            rc.IsCanChecked = false;
                        }
                        var dialogResult = rc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {

                            ees = rc.ElementExtractModel;
                            DataTable dt = new DataTable();
                            dt.Columns.AddRange(new DataColumn[] { new DataColumn("FdRuleNum"), new DataColumn("FdCodeCH"), new DataColumn("FdSourceName"), new DataColumn("FdPargraphName"), new DataColumn("FdIsQuanWen"), new DataColumn("FdWhere"), new DataColumn("EES_ID"), new DataColumn("IsML1") });
                            DataRow dr = dt.NewRow();
                            dr["FdRuleNum"] = "1";
                            dr["FdCodeCH"] = "通用";
                            //  string.IsNullOrEmpty(cbTreeViewSysData.Text) && string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "通用" :
                            //  (!string.IsNullOrEmpty(cbTreeViewSysData.Text) ? ("特殊：" + cbTreeViewSysData.Text) :
                            //  !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? "特殊：" + cbTreeViewSysCourt.Text :
                            //  !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCaseCause.Text :
                            //  !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? ("特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysData.Text) :
                            // !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCaseCause.Text :
                            //!string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text :
                            // "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text);
                            dr["FdPargraphName"] = "";
                            ees.EES_CodeCH = Convert.ToString(dr["FdCodeCH"]);
                            dr["FdSourceName"] = cbTreeViewDocType.Text;
                            ees.EES_SourceName = cbTreeViewDocType.Text;
                            dr["FdIsQuanWen"] = rc.ElementExtractModel.EES_SourceType == 4 ? "是" : "否";
                            dr["IsML1"] = rc.ElementExtractModel.EES_IsML;
                            dr["FdWhere"] = "";
                            if (string.IsNullOrEmpty(extractFeature.EES_ID))
                            {
                                dr["EES_ID"] = newid.CreateID("ElementExtractSource");
                                extractFeature.EES_ID = ees.EES_ID = dr["EES_ID"].ToString();
                            }
                            else
                            {
                                dr["EES_ID"] = extractFeature.EES_ID;
                                ees.EES_ID = extractFeature.EES_ID;
                            }
                            dt.Rows.Add(dr);
                            dgvFD.DataSource = dt;
                            if (!IsXinZeng && !string.IsNullOrEmpty(ees.EES_ID))
                            {
                                if (elementExtractSourceBll.ElementExtractSourceAdd(ees))
                                {
                                    MessageBox.Show("新增成功！");
                                }
                                else
                                {
                                    MessageBox.Show("新增失败！");
                                }
                            }

                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            MessageBox.Show("请将规则配置完整！");
                            return;
                        }
                    }
                }
                else if (dgvFD.Rows.Count > 0)
                {
                    MessageBox.Show("请选择列表中的数据进行修改或者删除后进行添加！");
                    return;
                }

            }//要素中心选择
            else if (tabControlModule.SelectedIndex == 1 && dgvYaoSu.Rows.Count == 1)
            {
                if (dgvYS.Rows.Count == 0)
                {
                    if (GetYYLiuCheng())
                    {
                        config cf = new config() { bookName = cbTreeViewDocType.Text };
                        RuleConfig rc = new RuleConfig(cf, 1, 0);
                        if (!string.IsNullOrEmpty(FDContent))
                        {
                            rc.LuoJiFDContent = FDContent;
                        }
                        var dialogResult = rc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {

                            ees = rc.ElementExtractModel;
                            DataTable dt = new DataTable();
                            dt.Columns.AddRange(new DataColumn[] { new DataColumn("YSRuleNum"), new DataColumn("YSCodeCH"), new DataColumn("YSSourceName"), new DataColumn("YSIsQuanWen"),
                            new DataColumn("YSIsYuanWen"), new DataColumn("YSIsLuJiDuan"), new DataColumn("YSIsLuJiDuanType"),
                        new DataColumn("YSIsLuJiDuanCode"), new DataColumn("YsName"), new DataColumn("YsWhere"), new DataColumn("EES_ID1"), new DataColumn("IsML")});
                            DataRow dr = dt.NewRow();
                            dr["YSRuleNum"] = "1";
                            dr["YSCodeCH"] = "通用";
                            //  string.IsNullOrEmpty(cbTreeViewSysData.Text) && string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "通用" :
                            //  (!string.IsNullOrEmpty(cbTreeViewSysData.Text) ? ("特殊：" + cbTreeViewSysData.Text) :
                            //  !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? "特殊：" + cbTreeViewSysCourt.Text :
                            //  !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCaseCause.Text :
                            //  !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? ("特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysData.Text) :
                            // !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCaseCause.Text :
                            //!string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text :
                            // "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text);
                            ees.EES_CodeCH = Convert.ToString(dr["YSCodeCH"]);
                            dr["YSSourceName"] = cbTreeViewDocType.Text;
                            ees.EES_SourceName = cbTreeViewDocType.Text;
                            switch (rc.ElementExtractModel.EES_SourceType)
                            {
                                case 4:
                                    dr["YSIsQuanWen"] = "是";
                                    break;
                                case 3:
                                    dr["YSIsYuanWen"] = "是";
                                    break;
                                case 1:
                                    dr["YSIsLuJiDuan"] = "是";
                                    dr["YSIsLuJiDuanType"] = "对话逻辑段";
                                    dr["YSIsLuJiDuanCode"] = ees.EES_Remark;
                                    break;
                                case 2:
                                    dr["YSIsLuJiDuan"] = "是";
                                    dr["YSIsLuJiDuanType"] = "逻辑段原文";
                                    dr["YSIsLuJiDuanCode"] = ees.EES_Remark;
                                    break;
                            }
                            dr["YsName"] = clicknode.FullPath;
                            dr["YsWhere"] = "";
                            if (string.IsNullOrEmpty(extractFeature.EES_ID))
                            {
                                dr["EES_ID1"] = newid.CreateID("ElementExtractSource");
                                extractFeature.EES_ID = ees.EES_ID = dr["EES_ID1"].ToString();
                            }
                            else
                            {
                                dr["EES_ID1"] = extractFeature.EES_ID;
                                ees.EES_ID = extractFeature.EES_ID;
                            }
                            dt.Rows.Add(dr);
                            dgvYS.DataSource = dt;
                            extractFeature.EES_ID = ees.EES_ID = dr["EES_ID1"].ToString();
                            if (!IsXinZeng && !string.IsNullOrEmpty(ees.EES_ID))
                            {
                                if (elementExtractSourceBll.ElementExtractSourceAdd(ees))
                                {
                                    MessageBox.Show("新增成功！");
                                }
                                else
                                {
                                    MessageBox.Show("新增失败！");
                                }
                            }
                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            MessageBox.Show("请将规则配置完整！");
                            return;
                        }
                    }
                }
                else if (dgvYS.Rows.Count > 0)
                {
                    MessageBox.Show("请选择列表中的数据进行修改或者删除后进行添加！");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }


        }

        /// <summary>
        /// 规则删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRuleDel_Click(object sender, EventArgs e)
        {
            if (tabControlModule.SelectedIndex == 0 && dgvYaoSu.Rows.Count == 1)
            {
                if (dgvFD.Rows.Count == 1)
                {
                    if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        if (IsXinZeng)
                        {
                            PublicMethod.ClearDataGridViewData(dgvFD);
                            extractFeature.EES_ID = "";
                        }
                        else if (dgvFD.Rows[0].Cells["EES_ID"].Value != null && !string.IsNullOrEmpty(dgvFD.Rows[0].Cells["EES_ID"].Value.ToString()))
                        {
                            if (GetYYLiuCheng())
                            {
                                string eesId = dgvFD.Rows[0].Cells["EES_ID"].Value.ToString();
                                if (elementExtractSourceBll.ElementExtractSourceDelete(eesId))
                                {
                                    MessageBox.Show("删除成功！");
                                    PublicMethod.ClearDataGridViewData(dgvFD);
                                    extractFeature.EES_ID = "";
                                }
                                else
                                {
                                    MessageBox.Show("删除失败！");
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("没有需要删除的数据！");
                    return;
                }
            }
            else if (tabControlModule.SelectedIndex == 1 && dgvYaoSu.Rows.Count == 1)
            {
                if (dgvYS.Rows.Count == 1)
                {
                    if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        if (IsXinZeng)
                        {
                            PublicMethod.ClearDataGridViewData(dgvYS);
                            extractFeature.EES_ID = "";
                        }
                        else if (!IsXinZeng && dgvYS.Rows[0].Cells["EES_ID1"].Value != null && !string.IsNullOrEmpty(dgvYS.Rows[0].Cells["EES_ID1"].Value.ToString()))
                        {
                            if (GetYYLiuCheng())
                            {
                                string eesId1 = dgvYS.Rows[0].Cells["EES_ID1"].Value.ToString();
                                if (elementExtractSourceBll.ElementExtractSourceDelete(eesId1))
                                {
                                    MessageBox.Show("删除成功！");
                                    PublicMethod.ClearDataGridViewData(dgvYS);
                                    extractFeature.EES_ID = "";
                                }
                                else
                                {
                                    MessageBox.Show("删除失败！");
                                }
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("没有需要删除的数据！");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }

        }

        /// <summary>
        /// 规则修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRuleUpdate_Click(object sender, EventArgs e)
        {
            //字段选择
            if (tabControlModule.SelectedIndex == 0 && dgvYaoSu.Rows.Count == 1)
            {
                if (dgvFD.Rows.Count == 1)
                {
                    if (GetYYLiuCheng())
                    {
                        config cf = new config() { bookName = cbTreeViewDocType.Text, IsQuanWen = dgvFD.Rows[0].Cells["FdIsQuanWen"].Value.ToString(), EES_ID = ees.EES_ID, IsUseML= dgvFD.Rows[0].Cells["IsML1"].Value==null?"":dgvFD.Rows[0].Cells["IsML1"].Value.ToString() };
                        RuleConfig rc = new RuleConfig(cf, 0, 1);
                        //if (clicknode.FullPath.Replace("\\", @"\").Split(new char[] { '\\' }).Length > 2)
                        //{
                        rc.IsCanChecked = true;
                        //}
                        //else
                        //{
                        //    rc.IsCanChecked = false;
                        //}
                        rc.IsAdd = IsXinZeng;
                        var dialogResult = rc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            ees.EES_ElementType = rc.ElementExtractModel.EES_ElementType;
                            ees.EES_SourceType = rc.ElementExtractModel.EES_SourceType;
                            DataTable dt = new DataTable();
                            dt.Columns.AddRange(new DataColumn[] { new DataColumn("FdRuleNum"), new DataColumn("FdCodeCH"), new DataColumn("FdSourceName"), new DataColumn("FdPargraphName"), new DataColumn("FdIsQuanWen"), new DataColumn("FdWhere"), new DataColumn("EES_ID"), new DataColumn("IsML1") });
                            DataRow dr = dt.NewRow();
                            dr["FdRuleNum"] = "1";
                            dr["FdCodeCH"] = "通用";
                            //string.IsNullOrEmpty(cbTreeViewSysData.Text) && string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "通用" :
                            //    (!string.IsNullOrEmpty(cbTreeViewSysData.Text) ? ("特殊：" + cbTreeViewSysData.Text) :
                            //    !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? "特殊：" + cbTreeViewSysCourt.Text :
                            //    !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCaseCause.Text :
                            //    !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? ("特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysData.Text) :
                            //   !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCaseCause.Text :
                            //  !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text :
                            //   "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text);
                            ees.EES_CodeCH = Convert.ToString(dr["FdCodeCH"]);
                            dr["FdSourceName"] = cbTreeViewDocType.Text;
                            ees.EES_SourceName = cbTreeViewDocType.Text;
                            dr["FdIsQuanWen"] = rc.ElementExtractModel.EES_SourceType == 4 ? "是" : "否";
                            dr["IsML1"] = rc.ElementExtractModel.EES_IsML.ToString() == "1" ? "是" : "否";
                            ees.EES_IsML = Convert.ToInt32(rc.ElementExtractModel.EES_IsML.ToString());
                            dr["FdWhere"] = "";
                            dr["EES_ID"] = "";
                            dt.Rows.Add(dr);
                            dgvFD.DataSource = dt;
                            if (!IsXinZeng && !string.IsNullOrEmpty(ees.EES_ID))
                            {
                                if (elementExtractSourceBll.ElementExtractSourceUpdate(ees))
                                {
                                    MessageBox.Show("修改成功！");
                                }
                                else
                                {
                                    MessageBox.Show("修改失败！");
                                }
                            }
                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            //MessageBox.Show("请将规则配置完整！");
                            return;
                        }
                    }
                }
                else if (dgvFD.Rows.Count == 0)
                {
                    MessageBox.Show("没有需要修改的数据");
                    return;
                }

            }
            else if (tabControlModule.SelectedIndex == 1 && dgvYaoSu.Rows.Count == 1)
            {
                if (dgvYS.Rows.Count == 1)
                {
                    if (GetYYLiuCheng())
                    {
                        config cf = new config()
                        {
                            bookName = cbTreeViewDocType.Text,
                            IsQuanWen = dgvYS.Rows[0].Cells["YSIsQuanWen"].Value.ToString(),
                            IsYuanWen = dgvYS.Rows[0].Cells["YSIsYuanWen"].Value.ToString(),
                            IsLuJiDuan = dgvYS.Rows[0].Cells["YSIsLuJiDuan"].Value.ToString(),
                            LuJiDuanCode = dgvYS.Rows[0].Cells["YSIsLuJiDuanCode"].Value.ToString(),
                            TiQuType = dgvYS.Rows[0].Cells["YSIsLuJiDuanType"].Value.ToString(),
                            EES_ID = ees.EES_ID,
                            IsUseML= dgvYS.Rows[0].Cells["IsML"].Value==null?"": dgvYS.Rows[0].Cells["IsML"].Value.ToString()
                        };
                        RuleConfig rc = new RuleConfig(cf, 1, 1);
                        rc.IsAdd = IsXinZeng;
                        if (!string.IsNullOrEmpty(FDContent))
                        {
                            rc.LuoJiFDContent = FDContent;
                        }
                        var dialogResult = rc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            // ees = rc.ElementExtractModel;
                            ees.EES_ElementType = rc.ElementExtractModel.EES_ElementType;
                            ees.EES_SourceType = rc.ElementExtractModel.EES_SourceType;
                            ees.EES_ParagraphName = rc.ElementExtractModel.EES_ParagraphName;
                            ees.EES_Remark = rc.ElementExtractModel.EES_Remark;
                            DataTable dt = new DataTable();
                            dt.Columns.AddRange(new DataColumn[] { new DataColumn("YSRuleNum"), new DataColumn("YSCodeCH"), new DataColumn("YSSourceName"), new DataColumn("YSIsQuanWen"),
                            new DataColumn("YSIsYuanWen"), new DataColumn("YSIsLuJiDuan"), new DataColumn("YSIsLuJiDuanType"),
                        new DataColumn("YSIsLuJiDuanCode"), new DataColumn("YsName"), new DataColumn("YsWhere"), new DataColumn("EES_ID1"), new DataColumn("IsML")});
                            DataRow dr = dt.NewRow();
                            dr["YSRuleNum"] = "1";
                            dr["YSCodeCH"] = "通用";
                            //string.IsNullOrEmpty(cbTreeViewSysData.Text) && string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "通用" :
                            //    (!string.IsNullOrEmpty(cbTreeViewSysData.Text) ? ("特殊：" + cbTreeViewSysData.Text) :
                            //    !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? "特殊：" + cbTreeViewSysCourt.Text :
                            //    !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCaseCause.Text :
                            //    !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) ? ("特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysData.Text) :
                            //   !string.IsNullOrEmpty(cbTreeViewSysData.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCaseCause.Text :
                            //  !string.IsNullOrEmpty(cbTreeViewSysCourt.Text) && !string.IsNullOrEmpty(cbTreeViewSysCaseCause.Text) ? "特殊：" + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text :
                            //   "特殊：" + cbTreeViewSysData.Text + " " + cbTreeViewSysCourt.Text + " " + cbTreeViewSysCaseCause.Text);
                            ees.EES_CodeCH = Convert.ToString(dr["YSCodeCH"]);
                            dr["YSSourceName"] = cbTreeViewDocType.Text;
                            dr["IsML"] = rc.ElementExtractModel.EES_IsML.ToString()=="1"?"是":"否";
                            ees.EES_SourceName = cbTreeViewDocType.Text;
                            ees.EES_IsML = Convert.ToInt32(rc.ElementExtractModel.EES_IsML.ToString());
                            switch (rc.ElementExtractModel.EES_SourceType)
                            {
                                case 4:
                                    dr["YSIsQuanWen"] = "是";
                                    break;
                                case 3:
                                    dr["YSIsYuanWen"] = "是";
                                    break;
                                case 1:
                                    dr["YSIsLuJiDuan"] = "是";
                                    dr["YSIsLuJiDuanType"] = "对话逻辑段";
                                    dr["YSIsLuJiDuanCode"] = ees.EES_Remark;
                                    break;
                                case 2:
                                    dr["YSIsLuJiDuan"] = "是";
                                    dr["YSIsLuJiDuanType"] = "逻辑段原文";
                                    dr["YSIsLuJiDuanCode"] = ees.EES_Remark;
                                    break;
                            }
                            dr["YsName"] = clicknode.FullPath;
                            dr["YsWhere"] = "";
                            dr["EES_ID1"] = "";
                            dt.Rows.Add(dr);
                            dgvYS.DataSource = dt;
                            if (!IsXinZeng && !string.IsNullOrEmpty(cf.EES_ID))
                            {
                                if (elementExtractSourceBll.ElementExtractSourceUpdate(ees))
                                {
                                    MessageBox.Show("修改成功！");
                                }
                                else
                                {
                                    MessageBox.Show("修改失败！");
                                }
                            }
                        }
                        else if (dialogResult == DialogResult.No)
                        {
                            //MessageBox.Show("请将规则配置完整！");
                            return;
                        }
                    }
                }
                else if (dgvYS.Rows.Count == 0)
                {
                    MessageBox.Show("没有需要修改的数据");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 已有值添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnArgumentOldAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(extractFeature.CM_ID))
            {
                //案由字典值可以多条 所以不进行提示
                DataTable dt = convertModelBll.GetConvertModeData(extractFeature.CM_ID);
                if (dt != null && dt.Rows.Count > 0)
                {
                    string CM_CMode = dt.Rows[0]["CM_CMode"].ToString();
                    if (!string.IsNullOrEmpty(CM_CMode) && CM_CMode == "0")
                    {
                        MessageBox.Show("属性已进行过案件字典值配置，请先删除案件字典值配置后再试！");
                        return;
                    }
                    else if (!string.IsNullOrEmpty(CM_CMode) && CM_CMode == "3" && cbxConvertMode.SelectedIndex == 0)
                    {
                        MessageBox.Show("属性已进行过案由字典值配置，请先删除案由字典值配置后再试！");
                        return;
                    }
                    else if (!string.IsNullOrEmpty(CM_CMode) && (CM_CMode == "1" || CM_CMode == "2"))
                    {
                        MessageBox.Show("属性已进行过函数值配置，请先删除函数值配置后再试！");
                        return;
                    }
                }
            }//案件类型配置
            if (cbxConvertMode.SelectedIndex == 0)
            {
                if (GetYYLiuCheng())
                {
                    string xmlPath = clicknode.FullPath;
                    //案件类型只能添加一条
                    if (dgvArgumentType.Rows.Count == 0 && dgvYaoSu.Rows.Count > 0)
                    {
                        ArgumentConfig dc = new ArgumentConfig(0);
                        dc.cm = new ConvertMode();
                        dc.cm.CM_ID = extractFeature.CM_ID;
                        dc.cm.CM_XmlPath = xmlPath;
                        dc.IsAdd = IsXinZeng;
                        dc.state = "新增";
                        dc.efId = extractFeature.EF_ID;
                        dc.DocType = CaseType;
                        var dialogResult = dc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            cm = dc.cm;
                            extractFeature.CM_ID = cm.CM_ID;
                            JZData();
                        }
                    }
                    else if (dgvArgumentType.Rows.Count == 1 && dgvYaoSu.Rows.Count > 0)
                    {
                        MessageBox.Show("请选择列表中的数据进行修改或者删除后进行添加！");
                        return;
                    }
                }
            }
            else if (cbxConvertMode.SelectedIndex == 1)
            {
                if (GetYYLiuCheng())
                {
                    ArgumentConfig dc;
                    if (dgvArgumentType.Rows.Count > 0)
                    {
                        string xmlPath = clicknode.FullPath;
                        if (dgvArgumentType.Rows[0].Cells["CM_CustomNew"].Value.ToString() == "0")
                        {
                            DataTable dt = convertModelBll.GetConvertModeDataNew(extractFeature.CM_ID);
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                ConvertMode cm = new ConvertMode();
                                cm.CM_ID = Snowflake.GetId().ToString();
                                cm.CM_Custom = 1;
                                cm.CM_CMode = 3;
                                cm.CM_Code = dt.Rows[0]["CM_Code"].ToString();
                                cm.CM_CodeCH = dt.Rows[0]["CM_CodeCH"].ToString();
                                cm.CM_UpdateTime = DateTime.Now;
                                cm.CM_XmlPath = xmlPath;
                                cm.CM_CaseType = CaseType;
                                convertModelBll.ConvertModeAdd(cm);
                                foreach (DataRow item in dt.Rows)
                                {
                                    ArgumentRelModel argumentModel = new ArgumentRelModel();
                                    argumentModel.AR_ID = Snowflake.GetId().ToString();
                                    argumentModel.CM_ID = cm.CM_ID;
                                    argumentModel.AT_ID = item["AT_ID"].ToString();
                                    argumentModel.AT_Code = item["AT_Code"].ToString();
                                    argumentModel.AR_CaseType = item["AR_CaseType"].ToString();
                                    argumentModel.AR_CauseCode = item["AR_CauseCode"].ToString();
                                    argumentModel.AR_UpdateTime = DateTime.Now;
                                    argumentRelBll.ArgumentRelAdd(argumentModel);
                                }
                                ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = cm.CM_ID };
                                efBll.ExtractFeatureUpdateCMID(ef);
                                extractFeature.CM_ID = cm.CM_ID;
                            }
                        }
                        dc = new ArgumentConfig(1, true);
                        dc.cm = new ConvertMode();
                        dc.cm.CM_ID = extractFeature.CM_ID;
                        dc.cm.CM_XmlPath = xmlPath;
                        dc.IsAdd = IsXinZeng;
                        dc.state = "新增";
                        dc.efId = extractFeature.EF_ID;
                        dc.DocType = CaseType;

                        string cmCCode = dgvArgumentType.Rows[0].Cells["CM_Code"].Value.ToString();
                        string cmCCodeCH = dgvArgumentType.Rows[0].Cells["CM_CodeCH"].Value.ToString();
                        dc.cm.CM_Code = cmCCode;
                        dc.cm.CM_CodeCH = cmCCodeCH;

                        var dialogResult = dc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            cm = dc.cm;
                            extractFeature.CM_ID = cm.CM_ID;
                            JZData();
                        }
                    }
                    else
                    {
                        string xmlPath = clicknode.FullPath;
                        //案由字典值配置
                        dc = new ArgumentConfig(1);
                        dc.cm = new ConvertMode();
                        dc.cm.CM_ID = extractFeature.CM_ID;
                        dc.cm.CM_XmlPath = xmlPath;
                        dc.IsAdd = IsXinZeng;
                        dc.state = "新增";
                        dc.efId = extractFeature.EF_ID;
                        dc.DocType = CaseType;
                        var dialogResult = dc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            cm = dc.cm;
                            extractFeature.CM_ID = cm.CM_ID;
                            JZData();
                        }
                    }
                }
            }
            else if (dgvYaoSu.Rows.Count == 0)
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 字典值删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnArgumentDel_Click(object sender, EventArgs e)
        {
            if (dgvYaoSu.Rows.Count == 1)
            {
                if (dgvArgumentType.Rows.Count > 0 && dgvArgumentType.SelectedRows.Count > 0)
                {
                    if (dgvArgumentType.Rows.Count == 1)
                    {
                        if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            //临时新增的 直接删掉即可 是默认的 删掉关系并且清空即可 不是默认的 删掉数据即可 多条的话删掉选中的那一条即可
                            if (IsXinZeng)
                            {
                                PublicMethod.ClearDataGridViewData(dgvArgumentType);
                                extractFeature.CM_ID = "";
                            }
                            else
                            if (dgvArgumentType.Rows[0].Cells["CM_CustomNew"].Value.ToString() == "0")
                            {
                                if (GetYYLiuCheng())
                                {
                                    extractFeature.CM_ID = "";
                                    ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                                    efBll.ExtractFeatureUpdateCMID(ef);
                                    if (IsExsitDefaultConfig())
                                    {
                                        MessageBox.Show("删除成功！该节点已有默认配置，如需修改转换方式，请先修改或者删除默认配置！");
                                    }
                                    else
                                    {
                                        MessageBox.Show("删除成功！");
                                    }
                                }
                            }
                            else if (dgvArgumentType.Rows[0].Cells["CM_ID"].Value != null && !string.IsNullOrEmpty(dgvArgumentType.Rows[0].Cells["CM_ID"].Value.ToString()))
                            {
                                if (GetYYLiuCheng())
                                {
                                    string cmID = dgvArgumentType.Rows[0].Cells["CM_ID"].Value.ToString();
                                    string arID = dgvArgumentType.SelectedRows[0].Cells["AR_ID1"].Value.ToString();
                                    if (convertModelBll.ConvertModeDelete(cmID) && argumentRelBll.ArgumentRelDelete(arID))
                                    {
                                        extractFeature.CM_ID = "";
                                        ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                                        efBll.ExtractFeatureUpdateCMID(ef);
                                        if (IsExsitDefaultConfig())
                                        {
                                            MessageBox.Show("删除成功！该节点已有默认配置，如需修改转换方式，请先修改或者删除默认配置！");
                                        }
                                        else
                                        {
                                            MessageBox.Show("删除成功！");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("删除失败！");
                                    }
                                }
                            }
                            PublicMethod.ClearDataGridViewData(dgvArgument);
                            PublicMethod.ClearDataGridViewData(dgvArgumentType);
                        }
                    }
                    else if (dgvArgumentType.Rows.Count > 1)
                    {
                        //判断是不是默认配置 默认配置得先转换为自己的
                        if (IsXinZeng)
                        {
                            PublicMethod.ClearDataGridViewData(dgvArgumentType);
                            extractFeature.CM_ID = "";
                        }
                        else
                        if (dgvArgumentType.Rows[0].Cells["CM_CustomNew"].Value.ToString() == "0")
                        {
                            if (GetYYLiuCheng())
                            {
                                string arId = "";
                                DataTable dt = convertModelBll.GetConvertModeDataNew(extractFeature.CM_ID);
                                if (dt != null && dt.Rows.Count > 0)
                                {
                                    ConvertMode cm = new ConvertMode();
                                    cm.CM_ID = Snowflake.GetId().ToString();
                                    cm.CM_Custom = 1;
                                    cm.CM_CMode = 3;
                                    cm.CM_Code = dt.Rows[0]["CM_Code"].ToString();
                                    cm.CM_CodeCH = dt.Rows[0]["CM_CodeCH"].ToString();
                                    cm.CM_UpdateTime = DateTime.Now;
                                    convertModelBll.ConvertModeAdd(cm);
                                    foreach (DataRow item in dt.Rows)
                                    {
                                        ArgumentRelModel argumentModel = new ArgumentRelModel();
                                        argumentModel.AR_ID = Snowflake.GetId().ToString();
                                        argumentModel.CM_ID = cm.CM_ID;
                                        argumentModel.AT_ID = item["AT_ID"].ToString();
                                        argumentModel.AT_Code = item["AT_Code"].ToString();
                                        argumentModel.AR_CaseType = item["AR_CaseType"].ToString();
                                        argumentModel.AR_CauseCode = item["AR_CauseCode"].ToString();
                                        argumentModel.AR_UpdateTime = DateTime.Now;
                                        argumentRelBll.ArgumentRelAdd(argumentModel);
                                        if (dgvArgumentType.SelectedRows[0].Cells["AT_IDNew"].Value.ToString() == argumentModel.AT_ID)
                                        {
                                            arId = argumentModel.AR_ID;
                                        }
                                    }
                                    ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = cm.CM_ID };
                                    efBll.ExtractFeatureUpdateCMID(ef);
                                    extractFeature.CM_ID = cm.CM_ID;
                                    if (argumentRelBll.ArgumentRelDelete(arId))
                                    {
                                        MessageBox.Show("删除成功！");
                                        dgvArgumentType.Rows.Remove(dgvArgumentType.SelectedRows[0]);
                                        JZData();
                                    }
                                    else
                                    {
                                        MessageBox.Show("删除失败！");
                                        return;
                                    }

                                }
                            }
                        }
                        else
                        {
                            if (GetYYLiuCheng())
                            {
                                string arID = dgvArgumentType.SelectedRows[0].Cells["AR_ID1"].Value.ToString();
                                if (argumentRelBll.ArgumentRelDelete(arID))
                                {
                                    MessageBox.Show("删除成功！");
                                    dgvArgumentType.Rows.Remove(dgvArgumentType.SelectedRows[0]);
                                }
                                else
                                {
                                    MessageBox.Show("删除失败！");
                                    return;
                                }
                            }
                        }

                    }
                }
                else
                {
                    MessageBox.Show("请选择需要删除的数据！");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 字典值修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnArgumentUpdate_Click(object sender, EventArgs e)
        {
            if (dgvYaoSu.Rows.Count == 1)
            {
                if (dgvArgumentType.Rows.Count == 1)
                {
                    if (GetYYLiuCheng())
                    {
                        ArgumentConfig dc = new ArgumentConfig(cbxConvertMode.SelectedIndex);
                        dc.cm = new ConvertMode();
                        if (dgvArgumentType.Rows[0].Cells["CM_ID"].Value != null && !string.IsNullOrEmpty(dgvArgumentType.Rows[0].Cells["CM_ID"].Value.ToString()))
                        {
                            dc.cm.CM_ID = dgvArgumentType.Rows[0].Cells["CM_ID"].Value.ToString();
                        }
                        dc.IsAdd = IsXinZeng;
                        dc.state = "修改";
                        dc.cm.CM_Code = dgvArgumentType.Rows[0].Cells["CM_Code"].Value.ToString();
                        dc.cm.CM_CodeCH = dgvArgumentType.Rows[0].Cells["CM_CodeCH"].Value.ToString();
                        string atId = dgvArgumentType.SelectedRows[0].Cells["AT_IDNew"].Value.ToString();

                        dc.cm.AT_Name = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Name"].ToString();
                        dc.cm.AT_Code = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Code"].ToString();
                        dc.cm.AT_ID = atId;
                        dc.cm.AT_WordsMode = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_WordsMode"].ToString();
                        dc.cm.CM_Custom = Convert.ToInt32(string.IsNullOrEmpty(dgvArgumentType.Rows[0].Cells["CM_CustomNew"].Value.ToString()) ? "0" : dgvArgumentType.Rows[0].Cells["CM_CustomNew"].Value.ToString());
                        dc.DocType = dc.cm.CM_CaseType = CaseType;
                        dc.arm = new ArgumentRelModel();
                        dc.arm.CM_ID = dc.cm.CM_ID;
                        dc.arm.AT_ID = atId;
                        dc.arm.AR_ID = dgvArgumentType.Rows[0].Cells["AR_ID1"].Value.ToString();
                        dc.arm.AT_Code = dc.cm.AT_Code;
                        dc.arm.AR_CauseCode = dgvArgumentType.Rows[0].Cells["AR_CauseCode1"].Value.ToString();

                        var dialogResult = dc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            PublicMethod.ClearDataGridViewData(dgvArgumentType);
                            cm = dc.cm;
                            extractFeature.CM_ID = cm.CM_ID;
                            ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                            efBll.ExtractFeatureUpdateCMID(ef);
                            JZData();
                        }
                        else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(dc.cm.CM_Code))
                        {
                            MessageBox.Show("请将字典值配置完整！");
                            return;
                        }
                    }
                }
                else if (dgvArgumentType.Rows.Count > 1)
                {
                    if (GetYYLiuCheng())
                    {
                        if (dgvArgumentType.Rows[0].Cells["CM_CustomNew"].Value.ToString() == "0")
                        {
                            DataTable dt = convertModelBll.GetConvertModeDataNew(extractFeature.CM_ID);
                            if (dt != null && dt.Rows.Count > 0)
                            {
                                ConvertMode cm = new ConvertMode();
                                cm.CM_ID = Snowflake.GetId().ToString();
                                cm.CM_Custom = 1;
                                cm.CM_CMode = 3;
                                cm.CM_Code = dt.Rows[0]["CM_Code"].ToString();
                                cm.CM_CodeCH = dt.Rows[0]["CM_CodeCH"].ToString();
                                cm.CM_UpdateTime = DateTime.Now;
                                cm.CM_CaseType = CaseType;

                                convertModelBll.ConvertModeAdd(cm);
                                foreach (DataRow item in dt.Rows)
                                {
                                    ArgumentRelModel argumentModel = new ArgumentRelModel();
                                    argumentModel.AR_ID = Snowflake.GetId().ToString();
                                    argumentModel.CM_ID = cm.CM_ID;
                                    argumentModel.AT_ID = item["AT_ID"].ToString();
                                    argumentModel.AT_Code = item["AT_Code"].ToString();
                                    argumentModel.AR_CaseType = item["AR_CaseType"].ToString();
                                    argumentModel.AR_CauseCode = item["AR_CauseCode"].ToString();
                                    argumentModel.AR_UpdateTime = DateTime.Now;
                                    argumentRelBll.ArgumentRelAdd(argumentModel);
                                }
                                ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = cm.CM_ID };
                                efBll.ExtractFeatureUpdateCMID(ef);
                                extractFeature.CM_ID = cm.CM_ID;
                            }
                        }
                        ArgumentConfig dc = new ArgumentConfig(cbxConvertMode.SelectedIndex, true);
                        dc.cm = new ConvertMode();
                        if (dgvArgumentType.SelectedRows[0].Cells["CM_ID"].Value != null && !string.IsNullOrEmpty(dgvArgumentType.SelectedRows[0].Cells["CM_ID"].Value.ToString()))
                        {
                            dc.cm.CM_ID = dgvArgumentType.SelectedRows[0].Cells["CM_ID"].Value.ToString();
                        }
                        dc.IsAdd = IsXinZeng;
                        dc.state = "修改";
                        dc.cm.CM_Code = dgvArgumentType.SelectedRows[0].Cells["CM_Code"].Value.ToString();
                        dc.cm.CM_CodeCH = dgvArgumentType.SelectedRows[0].Cells["CM_CodeCH"].Value.ToString();
                        string atId = dgvArgumentType.SelectedRows[0].Cells["AT_IDNew"].Value.ToString();

                        dc.cm.AT_Name = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Name"].ToString();
                        dc.cm.AT_Code = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Code"].ToString();
                        dc.cm.AT_ID = atId;
                        dc.cm.AT_WordsMode = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_WordsMode"].ToString();
                        dc.cm.CM_Custom = Convert.ToInt32(string.IsNullOrEmpty(dgvArgumentType.SelectedRows[0].Cells["CM_CustomNew"].Value.ToString()) ? "0" : dgvArgumentType.SelectedRows[0].Cells["CM_CustomNew"].Value.ToString());
                        dc.DocType = dc.cm.CM_CaseType = CaseType;

                        dc.arm = new ArgumentRelModel();
                        dc.arm.CM_ID = dc.cm.CM_ID;
                        dc.arm.AT_ID = atId;
                        dc.arm.AR_ID = dgvArgumentType.SelectedRows[0].Cells["AR_ID1"].Value.ToString();
                        dc.arm.AT_Code = dc.cm.AT_Code;
                        dc.arm.AR_CauseCode = dgvArgumentType.SelectedRows[0].Cells["AR_CauseCode1"].Value.ToString();

                        var dialogResult = dc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            PublicMethod.ClearDataGridViewData(dgvArgumentType);
                            cm = dc.cm;
                            extractFeature.CM_ID = cm.CM_ID;
                            ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                            efBll.ExtractFeatureUpdateCMID(ef);
                            JZData();
                        }
                        else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(dc.cm.CM_Code))
                        {
                            MessageBox.Show("请将字典值配置完整！");
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("没有需要修改的字典值数据");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 保存整体信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (dgvYaoSu.Rows.Count == 1 && IsXinZeng)
            {
                if (!string.IsNullOrEmpty(extractFeature.EF_ID) && !string.IsNullOrEmpty(extractInfo.EXI_ID))
                {
                    if (string.IsNullOrEmpty(extractFeature.EES_ID))
                    {
                        MessageBox.Show("请将规则配置配置完整后再试！");
                        return;
                    }
                    if (string.IsNullOrEmpty(extractFeature.RIU_ID))
                    {
                        MessageBox.Show("请将规则提取配置完整后再试！");
                        return;
                    }
                    //if (string.IsNullOrEmpty(extractFeature.CM_ID))
                    //{
                    //    MessageBox.Show("请将属性配置配置完整后再试！");
                    //    return;
                    //}
                    if (string.IsNullOrEmpty(extractFeature.RM_ID))
                    {
                        MessageBox.Show("请将数据返回方式配置完整后再试！");
                        return;
                    }
                    //if (!string.IsNullOrEmpty(extractFeature.CM_ID) && string.IsNullOrEmpty(cm.CM_Method))
                    //{
                    //    convertModelBll.ConvertModeAdd(cm);
                    //}
                    if (returnModelBll.ReturnModeAdd(rm) && elementExtractSourceBll.ElementExtractSourceAdd(ees) && extractFeatureBll.ExtractInfoAdd(extractInfo) && extractFeatureBll.ExtractFeatureAdd(extractFeature))
                    {
                        tabControlConfig.SelectedIndex = 0;
                        MessageBox.Show("添加成功！");
                        IsXinZeng = false;
                    }
                    else
                    {
                        MessageBox.Show("添加失败！");
                    }

                }

                #region MyRegion
                //}
                //else if (isBenShen == "是")
                //{
                //    //本身不用修改
                //    isAdd = true;
                //    return;
                //}
                //else if (dgvYaoSu.Rows[0].Cells["IsConfig"].Value.ToString() == "是")
                //{
                //    string tabName = tabControlModule.SelectedTab.Text;
                //    DataTable dt = new DataTable();
                //    if (tabName == "逻辑分段")
                //    {
                //        dt = extractFeatureBll.GetExtractFeatureData(clicknode.Tag.ToString(), 0,numbers["Paragraph"].ToString());
                //    }
                //    else if (tabName == "案件要素中心")
                //    {
                //        //2019-10-25 臨時添加
                //        //dt = extractFeatureBll.GetExtractFeatureData(clicknode.FullPath.ToString(), 1);
                //        dt = extractFeatureBll.GetExtractFeatureData(clicknode.FullPath.ToString(), 1, numbers["CaseExtraction"].ToString());
                //    }
                //    if (dt != null && dt.Rows.Count > 0)
                //    {
                //        //需要修改    
                //        extractFeatureBll.ExtractFeatureUpdate(extractFeature);
                //        MessageBox.Show("添加成功！");
                //        IsXinZeng = false;
                //    }
                //    else
                //    {
                //        if (extractFeatureBll.ExtractInfoAdd(extractInfo) && extractFeatureBll.ExtractFeatureAdd(extractFeature))
                //        {
                //            MessageBox.Show("添加成功！");
                //            IsXinZeng = false;
                //        }
                //    }


                //} 
                #endregion

                isAdd = true;
            }
            else
            {
                MessageBox.Show("没有需要保存的数据！");
                return;
            }
        }


        private void 全部展开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            clicknode.ExpandAll();
        }

        private void tvTxtParagraph_MouseDown(object sender, MouseEventArgs e)
        {
            var clickPoint = new Point(e.X, e.Y);
            editnode = tvTxtParagraph.GetNodeAt(clickPoint);
            if (editnode != null)//判断你点的是不是一个节点
            {
                editnode.ContextMenuStrip = contextMenuStrip1;
                tvTxtParagraph.SelectedNode = editnode;//选中这个节点
            }
        }

        private void tvElementData_MouseDown(object sender, MouseEventArgs e)
        {
            var clickPoint = new Point(e.X, e.Y);
            editnode = tvElementData.GetNodeAt(clickPoint);
            if (editnode != null)//判断你点的是不是一个节点
            {
                editnode.ContextMenuStrip = contextMenuStrip1;
                tvElementData.SelectedNode = editnode;//选中这个节点
            }
        }

        private void btnHanSuAdd_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(extractFeature.CM_ID))
            {
                DataTable dt = convertModelBll.GetConvertModeData(extractFeature.CM_ID);
                if (dt != null && dt.Rows.Count > 0)
                {
                    string CM_CMode = dt.Rows[0]["CM_CMode"].ToString();
                    if (!string.IsNullOrEmpty(CM_CMode) && CM_CMode == "0")
                    {
                        MessageBox.Show("属性已进行过案件字典值配置，请先删除案件字典值配置后再试！");
                        return;
                    }
                    else if (!string.IsNullOrEmpty(CM_CMode) && CM_CMode == "3" && cbxConvertModeConfig.SelectedIndex == 0)
                    {
                        MessageBox.Show("属性已进行过案由字典值配置，请先删除案由字典值配置后再试！");
                        return;
                    }
                    else if (!string.IsNullOrEmpty(CM_CMode) && (CM_CMode == "1" || CM_CMode == "2"))
                    {
                        MessageBox.Show("属性已进行过函数值配置，请先删除函数值配置后再试！");
                        return;
                    }
                }
                //DataTable dt = convertModelBll.GetConvertModeData(extractFeature.CM_ID);
                //if (dt != null && dt.Rows.Count > 0)
                //{
                //    string cm_Method = dt.Rows[0]["CM_Method"].ToString();
                //    string cm_Code = dt.Rows[0]["CM_Code"].ToString();
                //    if (!string.IsNullOrEmpty(cm_Code))
                //    {
                //        MessageBox.Show("属性已进行过字典值配置，请先删除字典值配置后再试！");
                //        return;
                //    }
                //}
            }
            if (dgvHanShu.Rows.Count == 0 && dgvYaoSu.Rows.Count > 0)
            {
                if (GetYYLiuCheng())
                {
                    HanShuConfig dc = new HanShuConfig();
                    dc.cm = new ConvertMode();
                    dc.cm.CM_ID = extractFeature.CM_ID;
                    dc.cm.CM_CaseType = CaseType;
                    dc.IsAdd = IsXinZeng;
                    dc.state = "新增";
                    dc.efId = extractFeature.EF_ID;
                    var dialogResult = dc.ShowDialog();
                    if (dialogResult == DialogResult.Yes)
                    {

                        cm = dc.cm;
                        DataTable showdt = new DataTable();
                        showdt.Columns.AddRange(new DataColumn[] { new DataColumn("HanShuName"), new DataColumn("HanShuParameter"), new DataColumn("CM_ID"), new DataColumn("CM_Custom"), new DataColumn("CM_MethodParameter"), new DataColumn("CM_Method") });
                        DataRow dr = showdt.NewRow();
                        dr["HanShuName"] = dicYaoSu.ContainsKey(cm.CM_Method) ? dicYaoSu[cm.CM_Method].Split(',')[0].ToString() : cm.CM_Method;
                        dr["CM_ID"] = cm.CM_ID;
                        dr["CM_Custom"] = cm.CM_Custom;
                        dr["CM_MethodParameter"] = cm.CM_MethodParameter;
                        dr["CM_Method"] = cm.CM_Method;
                        string cm_Parameter = cm.CM_MethodParameter;
                        if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm.CM_Method))
                        {
                            List<parameters> formats = dicYaoSuParams[cm.CM_Method];
                            if (formats.Count > 0)
                            {
                                foreach (parameters item in formats)
                                {
                                    if (item.name == cm_Parameter)
                                    {
                                        dr["HanShuParameter"] = item.remark;
                                        break;
                                    }
                                }
                            }
                        }
                        showdt.Rows.Add(dr);
                        dgvHanShu.DataSource = showdt;
                        extractFeature.CM_ID = cm.CM_ID;
                    }
                }
                //else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(cm.AT_ID))
                //{
                //    MessageBox.Show("请将数据返回方式配置完整！");
                //    return;
                //}
            }
            else if (dgvHanShu.Rows.Count > 0)
            {
                MessageBox.Show("请选择列表中的数据进行修改或者删除后进行添加！");
                return;
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }

        }

        /// <summary>
        /// 函数删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHanSuDel_Click(object sender, EventArgs e)
        {
            if (dgvYaoSu.Rows.Count == 1)
            {
                if (dgvHanShu.Rows.Count == 1)
                {
                    if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        if (IsXinZeng)
                        {
                            PublicMethod.ClearDataGridViewData(dgvHanShu);
                            extractFeature.CM_ID = "";
                        }
                        else
                        if (dgvHanShu.Rows[0].Cells["CM_Custom"].Value.ToString() == "0")
                        {
                            if (GetYYLiuCheng())
                            {
                                extractFeature.CM_ID = "";
                                ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                                efBll.ExtractFeatureUpdateCMID(ef);
                                if (IsExsitDefaultConfig())
                                {
                                    MessageBox.Show("删除成功！该节点已有默认配置，如需修改转换方式，请先修改或者删除默认配置！");
                                }
                                else
                                {
                                    MessageBox.Show("删除成功！");
                                }
                            }
                        }
                        else if (dgvHanShu.Rows[0].Cells["CM_ID1"].Value != null && !string.IsNullOrEmpty(dgvHanShu.Rows[0].Cells["CM_ID1"].Value.ToString()))
                        {
                            if (GetYYLiuCheng())
                            {
                                string cmID = dgvHanShu.Rows[0].Cells["CM_ID1"].Value.ToString();
                                if (convertModelBll.ConvertModeDelete(cmID))
                                {
                                    extractFeature.CM_ID = "";
                                    ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                                    efBll.ExtractFeatureUpdateCMID(ef);
                                    if (IsExsitDefaultConfig())
                                    {
                                        MessageBox.Show("删除成功！该节点已有默认配置，如需修改转换方式，请先修改或者删除默认配置！");
                                    }
                                    else
                                    {
                                        MessageBox.Show("删除成功！");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("删除失败！");
                                }
                            }
                        }
                        PublicMethod.ClearDataGridViewData(dgvHanShu);
                    }
                }
                else
                {
                    MessageBox.Show("没有需要删除的数据！");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 判断案件类型是否存在默认配置
        /// </summary>
        /// <returns></returns>
        public bool IsExsitDefaultConfig()
        {
            if (tabControlModule.SelectedTab.Text == "案件要素中心")
            {
                string xmlPath = clicknode.FullPath;
                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                DataTable dt1 = convertModelBll.GetConvertMode(xmlPath, caseType);
                if (dt1 != null && dt1.Rows.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }



        /// <summary>
        /// 函数修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnHanSuUpdate_Click(object sender, EventArgs e)
        {
            if (dgvYaoSu.Rows.Count == 1)
            {
                if (dgvHanShu.Rows.Count > 0)
                {
                    if (GetYYLiuCheng())
                    {
                        HanShuConfig dc = new HanShuConfig();
                        dc.cm = new ConvertMode();
                        if (dgvHanShu.Rows[0].Cells["CM_ID1"].Value != null && !string.IsNullOrEmpty(dgvHanShu.Rows[0].Cells["CM_ID1"].Value.ToString()))
                        {
                            dc.cm.CM_ID = dgvHanShu.Rows[0].Cells["CM_ID1"].Value.ToString();
                        }
                        dc.IsAdd = IsXinZeng;
                        dc.state = "修改";
                        dc.cm.CM_Method = dgvHanShu.Rows[0].Cells["CM_Method"].Value.ToString();
                        dc.cm.CM_Method = dgvHanShu.Rows[0].Cells["CM_Method"].Value.ToString();
                        dc.cm.CM_MethodParameter = dgvHanShu.Rows[0].Cells["HanShuParameter"].Value.ToString();
                        dc.cm.CM_MethodValue = dgvHanShu.Rows[0].Cells["CM_Method1"].Value.ToString();
                        dc.cm.CM_MethodParameterValue = dgvHanShu.Rows[0].Cells["CM_MethodParameter"].Value.ToString();
                        dc.cm.CM_Custom = Convert.ToInt32(string.IsNullOrEmpty(dgvHanShu.Rows[0].Cells["CM_Custom"].Value.ToString()) ? "0" : dgvHanShu.Rows[0].Cells["CM_Custom"].Value.ToString());
                        var dialogResult = dc.ShowDialog();
                        if (dialogResult == DialogResult.Yes)
                        {
                            PublicMethod.ClearDataGridViewData(dgvHanShu);
                            cm = dc.cm;
                            extractFeature.CM_ID = cm.CM_ID;
                            ExtractFeature ef = new ExtractFeature() { EF_ID = extractFeature.EF_ID, CM_ID = extractFeature.CM_ID };
                            efBll.ExtractFeatureUpdateCMID(ef);
                            DataTable showdt = new DataTable();
                            showdt.Columns.AddRange(new DataColumn[] { new DataColumn("HanShuName"), new DataColumn("HanShuParameter"), new DataColumn("CM_ID"), new DataColumn("CM_Custom"), new DataColumn("CM_MethodParameter"), new DataColumn("CM_Method") });
                            DataRow dr = showdt.NewRow();
                            dr["HanShuName"] = dicYaoSu.ContainsKey(cm.CM_Method) ? dicYaoSu[cm.CM_Method].Split(',')[0].ToString() : cm.CM_Method;
                            dr["CM_ID"] = cm.CM_ID;
                            dr["CM_Custom"] = cm.CM_Custom;
                            dr["CM_MethodParameter"] = cm.CM_MethodParameter;
                            dr["CM_Method"] = cm.CM_Method;
                            string cm_Parameter = cm.CM_MethodParameter;
                            //foreach (var item in dicYaoSu.Keys)
                            //{
                            //if (dicYaoSu[item] == cm.CM_Method)
                            //{
                            if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm.CM_Method))
                            {
                                List<parameters> formats = dicYaoSuParams[cm.CM_Method];
                                if (formats.Count > 0)
                                {
                                    foreach (parameters item1 in formats)
                                    {
                                        if (item1.name == cm_Parameter)
                                        {
                                            dr["HanShuParameter"] = item1.remark;
                                            break;
                                        }
                                    }
                                }
                                // }
                                //}
                            }
                            if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm.CM_Method))
                            {

                            }
                            showdt.Rows.Add(dr);
                            dgvHanShu.DataSource = showdt;

                        }
                        else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(dc.cm.CM_Method))
                        {
                            MessageBox.Show("请将函数值配置完整！");
                            return;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("没有需要修改的函数值数据");
                    return;
                }
            }
            else
            {
                MessageBox.Show("请先进行关系配置后再试！");
                return;
            }
        }

        /// <summary>
        /// 一键关联
        /// 备注：一键关联的逻辑为选择当前的节点，从当前节点开始从弹出的选择关联的模块中取关联模块xmlPath相同的数据，如果存在则将4个关系和当前的模块保存入库，否则跳过，保存的数据只会比关联模块少
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddAll_Click(object sender, EventArgs e)
        {
            try
            {
                if (clicknode != null)
                {
                    string tabName = tabControlModule.SelectedTab.Text;
                    DataTable dt = new DataTable();
                    if (tabName == "逻辑分段")
                    {
                        dt = extractFeatureBll.GetModuleCodeData(clicknode.Tag.ToString(), 0, numbers["Paragraph"][0].ToString());
                    }
                    else if (tabName == "案件要素中心")
                    {
                        dt = extractFeatureBll.GetModuleCodeData(clicknode.FullPath.ToString(), 1, numbers["CaseExtraction"][0].ToString());
                    }
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        ModuleSelect cs = new ModuleSelect(dt);
                        cs.ShowDialog();
                        if (cs.DialogResult == DialogResult.Yes && !string.IsNullOrEmpty(cs.Code))
                        {
                            this.Cursor = Cursors.WaitCursor;
                            lblTiShi.Text = "正在添加中，请稍后......";
                            if (tabName == "逻辑分段")
                            {
                                addNum = 0;
                                Task.Run(() =>
                                {
                                    GetTreeViewNodeParagraph(clicknode, cs.Code);
                                    MessageBox.Show($"成功添加{addNum}条");
                                    lblTiShi.Text = "添加完成";
                                    Thread.Sleep(1000);
                                    lblTiShi.Text = "";
                                    this.Cursor = Cursors.Default;
                                    LoadYaoSuData();
                                });
                            }
                            else if (tabName == "案件要素中心")
                            {
                                addNum = 0;
                                Task.Run(() =>
                                {
                                    GetTreeViewNodeYaoSu(clicknode, cs.Code);
                                    MessageBox.Show($"成功添加{addNum}条");
                                    lblTiShi.Text = "添加完成";
                                    Thread.Sleep(1000);
                                    lblTiShi.Text = "";
                                    this.Cursor = Cursors.Default;
                                    LoadYaoSuData();

                                });

                            }

                        }
                    }
                    else
                    {
                        MessageBox.Show("没有可以关联的模块！");
                        return;
                    }


                }
                else
                {
                    MessageBox.Show("请先选择需要关联的节点后再试！");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加出错：" + ex.Message);
            }
        }

        /// <summary>
        /// 逻辑分段添加
        /// </summary>
        /// <param name="node"></param>
        public void GetTreeViewNodeParagraph(TreeNode node, string moduleName)
        {
            try
            {
                DataTable dtParagraph = extractFeatureBll.GetExtractFeatureData(node.Tag.ToString(), 0, moduleName);
                if (dtParagraph != null && dtParagraph.Rows.Count > 0)
                {
                    extractFeatureBll.DeleteExtractFeature(dtParagraph.Rows[0]["EXI_ID"].ToString(), numbers["CaseExtraction"][0].ToString());

                    ExtractFeature extractFeatureParagraph = new ExtractFeature();
                    extractFeatureParagraph.EF_ID = newid.CreateID("ExtractFeature");
                    extractFeatureParagraph.EXI_ID = dtParagraph.Rows[0]["EXI_ID"].ToString();
                    extractFeatureParagraph.EF_ModuleCode = numbers["CaseExtraction"][0].ToString();
                    extractFeatureParagraph.EES_ID = dtParagraph.Rows[0]["EES_ID"].ToString();
                    extractFeatureParagraph.RIU_ID = dtParagraph.Rows[0]["RIU_ID"].ToString();
                    extractFeatureParagraph.CM_ID = dtParagraph.Rows[0]["CM_ID"].ToString();
                    extractFeatureParagraph.RM_ID = dtParagraph.Rows[0]["RM_ID"].ToString();
                    if (extractFeatureBll.ExtractFeatureAdd(extractFeatureParagraph))
                    {
                        addNum++;
                    }
                }

                foreach (TreeNode item in node.Nodes)
                {
                    GetTreeViewNodeParagraph(item, moduleName);
                }

                #region MyRegion
                //else
                //{
                //    dtParagraph = extractFeatureBll.GetExtractFeatureData(node.Tag.ToString(), 0, numbers["Paragraph"][1].ToString());
                //    if (dtParagraph != null && dtParagraph.Rows.Count > 0)
                //    {
                //        ExtractFeature extractFeatureParagraph = new ExtractFeature();
                //        ExtractInfo extractInfoParagraph = new ExtractInfo();
                //        extractFeatureParagraph.EES_ID = dtParagraph.Rows[0]["EES_ID"].ToString();
                //        extractFeatureParagraph.RIU_ID = dtParagraph.Rows[0]["RIU_ID"].ToString();
                //        extractFeatureParagraph.CM_ID = dtParagraph.Rows[0]["CM_ID"].ToString();
                //        extractFeatureParagraph.RM_ID = dtParagraph.Rows[0]["RM_ID"].ToString();
                //        extractFeatureParagraph.EF_ID = newid.CreateID("ExtractFeature");
                //        extractInfoParagraph.EXI_ID = newid.CreateID("ExtractInfo");
                //        extractFeatureParagraph.EXI_ID = extractInfoParagraph.EXI_ID;
                //        //extractFeatureParagraph.EF_FeatureName = filePathName;
                //        extractInfoParagraph.EXI_DataMode = 2;
                //        //extractInfoParagraph.EXI_ModuleCode = numbers["Paragraph"][1].ToString();
                //        extractInfoParagraph.EXI_ParagraCode = node.Tag.ToString();
                //        if (extractFeatureBll.ExtractInfoAdd(extractInfoParagraph) && extractFeatureBll.ExtractFeatureAdd(extractFeatureParagraph))
                //        {
                //            addNum++;
                //        }
                //    }
                //} 
                #endregion

            }
            catch (Exception ex)
            {
                MessageBox.Show("逻辑分段添加发生错误：" + ex.Message);
            }
        }

        /// <summary>
        /// 要素添加
        /// </summary>
        /// <param name="node"></param>
        public void GetTreeViewNodeYaoSu(TreeNode node, string moduleName)
        {
            try
            {
                DataTable dtParagraph = extractFeatureBll.GetExtractFeatureData(node.FullPath.ToString(), 1, moduleName);
                if (dtParagraph != null && dtParagraph.Rows.Count > 0)
                {
                    extractFeatureBll.DeleteExtractFeature(dtParagraph.Rows[0]["EXI_ID"].ToString(), numbers["CaseExtraction"][0].ToString());

                    ExtractFeature extractFeatureParagraph = new ExtractFeature();
                    extractFeatureParagraph.EF_ID = newid.CreateID("ExtractFeature");
                    extractFeatureParagraph.EXI_ID = dtParagraph.Rows[0]["EXI_ID"].ToString();
                    extractFeatureParagraph.EF_ModuleCode = numbers["CaseExtraction"][0].ToString();
                    extractFeatureParagraph.EES_ID = dtParagraph.Rows[0]["EES_ID"].ToString();
                    extractFeatureParagraph.RIU_ID = dtParagraph.Rows[0]["RIU_ID"].ToString();
                    extractFeatureParagraph.CM_ID = dtParagraph.Rows[0]["CM_ID"].ToString();
                    extractFeatureParagraph.RM_ID = dtParagraph.Rows[0]["RM_ID"].ToString();
                    if (extractFeatureBll.ExtractFeatureAdd(extractFeatureParagraph))
                    {
                        addNum++;
                    }
                }
                foreach (TreeNode item in node.Nodes)
                {
                    GetTreeViewNodeYaoSu(item, moduleName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("要素添加发生错误：" + ex.Message);
            }

            #region MyRegion
            //else
            //{
            //    dtParagraph = extractFeatureBll.GetExtractFeatureData(node.FullPath.ToString(), 1, numbers["CaseExtraction"][1].ToString());
            //    if (dtParagraph != null && dtParagraph.Rows.Count > 0)
            //    {
            //        ExtractFeature extractFeatureParagraph = new ExtractFeature();
            //        ExtractInfo extractInfoParagraph = new ExtractInfo();
            //        extractFeatureParagraph.EES_ID = dtParagraph.Rows[0]["EES_ID"].ToString();
            //        extractFeatureParagraph.RIU_ID = dtParagraph.Rows[0]["RIU_ID"].ToString();
            //        extractFeatureParagraph.CM_ID = dtParagraph.Rows[0]["CM_ID"].ToString();
            //        extractFeatureParagraph.RM_ID = dtParagraph.Rows[0]["RM_ID"].ToString();
            //        extractFeatureParagraph.EF_ID = newid.CreateID("ExtractFeature");
            //        extractInfoParagraph.EXI_ID = newid.CreateID("ExtractInfo");
            //        extractFeatureParagraph.EXI_ID = extractInfoParagraph.EXI_ID;
            //        //extractFeatureParagraph.EF_FeatureName = filePathName;
            //        extractInfoParagraph.EXI_DataMode = 1;
            //        //extractInfoParagraph.EXI_ModuleCode = numbers["CaseExtraction"][1].ToString();
            //        extractInfoParagraph.EXI_XmlPath = node.FullPath.ToString();
            //        if (extractFeatureBll.ExtractInfoAdd(extractInfoParagraph) && extractFeatureBll.ExtractFeatureAdd(extractFeatureParagraph))
            //        {
            //            addNum++;
            //        }
            //    }
            //} 
            #endregion

        }

        /// <summary>
        /// 属性规则配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cbxConvertModeConfig_SelectedIndexChanged(object sender, EventArgs e)
        {
            //0案件字典1案由字典2函数
            if (cbxConvertModeConfig.SelectedIndex == 0 || cbxConvertModeConfig.SelectedIndex == 1)
            {
                panelDictionaryConfig.Visible = true;
                panelDictionaryConfig.Dock = DockStyle.Fill;
                panelHanShuConfig.Dock = DockStyle.None;
                panelHanShuConfig.Visible = false;
                loadDictionaryConfig();
            }
            else if (cbxConvertModeConfig.SelectedIndex == 2)
            {
                panelHanShuConfig.Visible = true;
                panelHanShuConfig.Dock = DockStyle.Fill;
                loadHanShuConfig();
                panelDictionaryConfig.Dock = DockStyle.None;
                panelDictionaryConfig.Visible = false;
            }
        }

        /// <summary>
        /// 加载字典值
        /// </summary>
        private void loadDictionaryConfig()
        {
            if (clicknodeConfig != null)
            {
                string xmlPath = clicknodeConfig.FullPath;
                //案件类型
                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                DataTable dt = convertModelBll.GetConvertMode(xmlPath, caseType);
                if (dt != null && dt.Rows.Count > 0)
                {
                    if (dt.Rows[0]["CM_CMode"].ToString() == "0")
                    {
                        cbxConvertModeConfig.SelectedIndex = 0;
                        LoadData(xmlPath, caseType, cbxConvertModeConfig.SelectedIndex);
                    }
                    else if (dt.Rows[0]["CM_CMode"].ToString() == "3")
                    {
                        cbxConvertModeConfig.SelectedIndex = 1;
                        LoadData(xmlPath, caseType, cbxConvertModeConfig.SelectedIndex);
                    }
                    else if (dt.Rows[0]["CM_CMode"].ToString() == "1" || dt.Rows[0]["CM_CMode"].ToString() == "2")
                    {
                        cbxConvertModeConfig.SelectedIndex = 2;
                    }
                }

                //DataTable dt = convertModelBll.GetConvertModeData(xmlPath, caseType);
                //if (dt != null && dt.Rows.Count > 0 )
                //{
                //    //string atName = string.Empty;
                //    //string atConstituteMode = string.Empty;
                //    //string cm_Method = dt.Rows[0]["CM_Method"].ToString();
                //    //string cm_Code = dt.Rows[0]["CM_Code"].ToString();

                //    //dt = dt.Select("CM_CMode=0").CopyToDataTable();
                //    //if (!string.IsNullOrEmpty(cm_Code))
                //    //{
                //    //    if (sysArgumentTypeData.Select(" AT_ID='" + dt.Rows[0]["AT_ID"].ToString() + "' ").Length > 0)
                //    //    {
                //    //        DataRow dr1 = sysArgumentTypeData.Select(" AT_ID='" + dt.Rows[0]["AT_ID"].ToString() + "' ").CopyToDataTable<DataRow>().Rows[0];
                //    //        atName = dr1["AT_Name"].ToString();
                //    //        atConstituteMode = dr1["AT_WordsMode"].ToString();
                //    //    }
                //    //    DataTable showdt = new DataTable();
                //    //    showdt.Columns.AddRange(new DataColumn[] { new DataColumn("CM_Code"), new DataColumn("CM_CodeCH"), new DataColumn("AT_Code"), new DataColumn("AT_Name"), new DataColumn("AT_WordsMode"), new DataColumn("CM_ID"), new DataColumn("AT_ID") });
                //    //    DataRow dr = showdt.NewRow();
                //    //    dr["CM_Code"] = dt.Rows[0]["CM_Code"];
                //    //    dr["CM_CodeCH"] = dt.Rows[0]["CM_CodeCH"];
                //    //    dr["AT_Code"] = dt.Rows[0]["AT_Code"];
                //    //    dr["AT_Name"] = atName;
                //    //    dr["AT_WordsMode"] = atConstituteMode;
                //    //    dr["CM_ID"] = dt.Rows[0]["CM_ID"];
                //    //    dr["AT_ID"] = dt.Rows[0]["AT_ID"].ToString();
                //    //    showdt.Rows.Add(dr);
                //    //    dgvArgumentTypeConfig.DataSource = showdt;
                //    //    cm = new ConvertMode()
                //    //    {
                //    //        CM_ID = dt.Rows[0]["CM_ID"].ToString(),
                //    //        CM_Code = dt.Rows[0]["CM_Code"].ToString(),
                //    //        CM_CodeCH = dt.Rows[0]["CM_CodeCH"].ToString(),
                //    //        CM_CMode = Convert.ToInt32(dt.Rows[0]["CM_CMode"].ToString()),
                //    //        AT_ID = dt.Rows[0]["AT_ID"].ToString(),
                //    //        AT_Code = dt.Rows[0]["AT_Code"].ToString()
                //    //    };
                //    //    dgvArgumentConfig.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(cm.AT_ID);
                //    //}

                //}
                //else
                //{
                //    DataTable dt1 = (DataTable)dgvArgumentTypeConfig.DataSource;
                //    if (dt1 != null)
                //    { dt1.Rows.Clear(); }
                //    dgvArgumentTypeConfig.DataSource = dt1;
                //}
            }
        }

        /// <summary>
        /// 函数配置加载
        /// </summary>
        private void loadHanShuConfig()
        {
            if (clicknodeConfig != null)
            {
                string xmlPath = clicknodeConfig.FullPath;
                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                DataTable dt = convertModelBll.GetConvertModeHanShuData(xmlPath, caseType);
                if (dt != null && dt.Rows.Count > 0 && dt.Select("CM_CMode in(1,2) ").Length > 0)
                {
                    dt = dt.Select("CM_CMode in(1,2)").CopyToDataTable();
                    DataTable showdt = new DataTable();
                    showdt.Columns.AddRange(new DataColumn[] { new DataColumn("HanShuName"), new DataColumn("HanShuParameter"), new DataColumn("CM_ID"), new DataColumn("CM_Custom") });
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        string cm_Method = dt.Rows[0]["CM_Method"].ToString();
                        string cm_ID = dt.Rows[0]["CM_ID"].ToString();
                        string cm_Parameter = dt.Rows[0]["CM_MethodParameter"].ToString();
                        DataRow dr = showdt.NewRow();
                        dr["HanShuName"] = dicYaoSu.ContainsKey(cm_Method) ? dicYaoSu[cm_Method].Split(',')[0].ToString() : cm_Method;
                        if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm_Method))
                        {
                            List<parameters> formats = dicYaoSuParams[cm_Method];
                            if (formats.Count > 0)
                            {
                                foreach (parameters item in formats)
                                {
                                    if (item.name == cm_Parameter)
                                    {
                                        dr["HanShuParameter"] = item.remark;
                                        break;
                                    }
                                }
                            }
                        }
                        else
                        {
                            dr["HanShuParameter"] = "";
                        }
                        dr["CM_ID"] = cm_ID;
                        dr["CM_Custom"] = 1;
                        showdt.Rows.Add(dr);
                        dgvHanShuConfig.DataSource = showdt;
                    }
                }
                else
                {
                    DataTable dt1 = (DataTable)dgvHanShuConfig.DataSource;
                    if (dt1 != null)
                    { dt1.Rows.Clear(); }
                    dgvHanShuConfig.DataSource = dt1;
                }
            }





        }

        /// <summary>
        /// 属性配置函数添加
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            if (clicknodeConfig == null)
            {
                MessageBox.Show("请先选择需要配置的节点后再试！");
                return;
            }
            string xmlPath = clicknodeConfig.FullPath;
            string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
            caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
            if (dgvHanShuConfig.Rows.Count > 0)
            {
                MessageBox.Show("属性已进行过函数值配置，请先删除函数值配置后再试！");
                return;
            }
            else
            {
                DataTable dtDic = convertModelBll.GetConvertModeData(xmlPath, caseType);
                if (dtDic != null && dtDic.Rows.Count > 0)
                {
                    MessageBox.Show("属性已进行过案件字典值配置，请先删除案件字典值配置后再试！");
                    return;
                }
                DataTable dtArgument = argumentRelBll.GetConvertModeData(xmlPath, caseType);
                if (dtArgument != null && dtArgument.Rows.Count > 0 && cbxConvertModeConfig.SelectedIndex == 0)
                {
                    MessageBox.Show("属性已进行过案由字典值配置，请先删除案由字典值配置后再试！");
                    return;
                }
            }
            if (dgvHanShuConfig.Rows.Count == 0)
            {
                HanShuConfigNew dc = new HanShuConfigNew();
                dc.cm = new ConvertMode();
                dc.cm.CM_XmlPath = xmlPath;
                dc.cm.CM_Custom = 0;
                dc.cm.CM_CaseType = caseType;
                dc.state = "新增";
                dc.cm.CM_ID = Snowflake.GetId().ToString();
                var dialogResult = dc.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    cm = dc.cm;
                    DataTable showdt = new DataTable();
                    showdt.Columns.AddRange(new DataColumn[] { new DataColumn("HanShuName"), new DataColumn("HanShuParameter"), new DataColumn("CM_ID"), new DataColumn("CM_Custom") });
                    DataRow dr = showdt.NewRow();
                    dr["HanShuName"] = dicYaoSu.ContainsKey(cm.CM_Method) ? dicYaoSu[cm.CM_Method].Split(',')[0].ToString() : cm.CM_Method;
                    dr["CM_ID"] = cm.CM_ID;
                    dr["CM_Custom"] = 1;
                    string cm_Parameter = cm.CM_MethodParameter;
                    if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm.CM_Method))
                    {
                        List<parameters> formats = dicYaoSuParams[cm.CM_Method];
                        if (formats.Count > 0)
                        {
                            foreach (parameters item in formats)
                            {
                                if (item.name == cm_Parameter)
                                {
                                    dr["HanShuParameter"] = item.remark;
                                    break;
                                }
                            }
                        }
                    }
                    showdt.Rows.Add(dr);
                    dgvHanShuConfig.DataSource = showdt;
                }
            }
            else if (dgvHanShuConfig.Rows.Count > 0)
            {
                MessageBox.Show("请选择列表中的数据进行修改或者删除后进行添加！");
                return;
            }

        }

        private void tvElementsConfig_AfterCheck(object sender, TreeViewEventArgs e)
        {
            if (clicknodeConfig != null)
            {
                if (clicknodeConfig.Text != e.Node.Text)
                {
                    clicknodeConfig.ForeColor = Color.Black;
                }
                else if (clicknodeConfig.Text == e.Node.Text)
                {
                    return;
                }
            }
            if (e.Node != null)
            {
                clicknodeConfig = e.Node;//保存节点
                clicknodeConfig.ForeColor = Color.Red;
                PublicMethod.ClearDataGridViewData(dgvHanShuConfig);
                PublicMethod.ClearDataGridViewData(dgvArgumentTypeConfig);
                PublicMethod.ClearDataGridViewData(dgvArgumentConfig);
                cbxConvertModeConfig.SelectedIndex = 0;
                cbxConvertModeConfig_SelectedIndexChanged(null, null);
            }
        }

        /// <summary>
        /// 函数配置删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            if (dgvHanShuConfig.Rows.Count == 1)
            {
                if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (dgvHanShuConfig.Rows[0].Cells["CM_IDConfig"].Value != null && !string.IsNullOrEmpty(dgvHanShuConfig.Rows[0].Cells["CM_IDConfig"].Value.ToString()))
                    {
                        string cmID = dgvHanShuConfig.Rows[0].Cells["CM_IDConfig"].Value.ToString();
                        if (convertModelBll.ConvertModeDeleteConfig(cmID))
                        {
                            MessageBox.Show("删除成功！");
                        }
                        else
                        {
                            MessageBox.Show("删除失败！");
                        }
                    }
                    PublicMethod.ClearDataGridViewData(dgvHanShuConfig);
                }
            }
            else
            {
                MessageBox.Show("没有需要删除的数据！");
                return;
            }
        }

        /// <summary>
        /// 函数配置修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            if (dgvHanShuConfig.Rows.Count > 0)
            {
                HanShuConfigNew dc = new HanShuConfigNew();
                dc.cm = new ConvertMode();
                if (dgvHanShuConfig.Rows[0].Cells["CM_IDConfig"].Value != null && !string.IsNullOrEmpty(dgvHanShuConfig.Rows[0].Cells["CM_IDConfig"].Value.ToString()))
                {
                    dc.cm.CM_ID = dgvHanShuConfig.Rows[0].Cells["CM_IDConfig"].Value.ToString();
                }
                dc.state = "修改";
                dc.cm.CM_Method = dgvHanShuConfig.Rows[0].Cells["HanShuNameConfig"].Value.ToString();
                dc.cm.CM_MethodParameter = dgvHanShuConfig.Rows[0].Cells["HanShuParameterConfig"].Value.ToString();
                var dialogResult = dc.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    PublicMethod.ClearDataGridViewData(dgvHanShuConfig);
                    cm = dc.cm;
                    DataTable showdt = new DataTable();
                    showdt.Columns.AddRange(new DataColumn[] { new DataColumn("HanShuName"), new DataColumn("HanShuParameter"), new DataColumn("CM_ID"), new DataColumn("CM_Custom") });
                    DataRow dr = showdt.NewRow();
                    dr["HanShuName"] = dicYaoSu.ContainsKey(cm.CM_Method) ? dicYaoSu[cm.CM_Method].Split(',')[0].ToString() : cm.CM_Method;
                    dr["CM_ID"] = cm.CM_ID;
                    dr["CM_Custom"] = cm.CM_Custom;
                    string cm_Parameter = cm.CM_MethodParameter;
                    //foreach (var item in dicYaoSu.Keys)
                    //{
                    //if (dicYaoSu[item] == cm.CM_Method)
                    //{
                    if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm.CM_Method))
                    {
                        List<parameters> formats = dicYaoSuParams[cm.CM_Method];
                        if (formats.Count > 0)
                        {
                            foreach (parameters item1 in formats)
                            {
                                if (item1.name == cm_Parameter)
                                {
                                    dr["HanShuParameter"] = item1.remark;
                                    break;
                                }
                            }
                        }
                        // }
                        //}
                    }
                    if (!string.IsNullOrEmpty(cm_Parameter) && dicYaoSuParams.ContainsKey(cm.CM_Method))
                    {

                    }
                    showdt.Rows.Add(dr);
                    dgvHanShuConfig.DataSource = showdt;
                }
                else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(dc.cm.CM_Method))
                {
                    MessageBox.Show("请将函数值配置完整！");
                    return;
                }
            }
            else
            {
                MessageBox.Show("没有需要修改的函数值数据");
                return;
            }

        }

        /// <summary>
        /// 已有值字典值配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button6_Click(object sender, EventArgs e)
        {
            if (clicknodeConfig == null)
            {
                MessageBox.Show("请先选择需要配置的节点后再试！");
                return;
            }
            string xmlPath = clicknodeConfig.FullPath;
            string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
            caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
            DataTable dtDic = convertModelBll.GetConvertModeData(xmlPath, caseType);
            if (dtDic != null && dtDic.Rows.Count > 0)
            {
                MessageBox.Show("属性已进行过案件字典值配置，请先删除案件字典值配置后再试！");
                return;
            }
            DataTable dtArgument = argumentRelBll.GetConvertModeData(xmlPath, caseType);
            if (dtArgument != null && dtArgument.Rows.Count > 0 && cbxConvertModeConfig.SelectedIndex == 0)
            {
                MessageBox.Show("属性已进行过案由字典值配置，请先删除案由字典值配置后再试！");
                return;
            }
            DataTable dtHanShu = convertModelBll.GetConvertModeHanShuData(xmlPath, caseType);
            if (dtHanShu != null && dtHanShu.Rows.Count > 0)
            {
                MessageBox.Show("属性已进行过函数值配置，请先删除函数值配置后再试！");
                return;
            }
            if (cbxConvertModeConfig.SelectedIndex == 0 && dgvArgumentTypeConfig.Rows.Count > 0)
            {
                MessageBox.Show("请选择列表中的数据进行修改或者删除后进行添加！");
                return;
            }
            //0案件字典值配置
            if (cbxConvertModeConfig.SelectedIndex == 0)
            {
                ArgumentConfigNew dc = new ArgumentConfigNew(0);
                dc.cm = new ConvertMode();
                dc.cm.CM_XmlPath = xmlPath;
                dc.cm.CM_Custom = 0;
                dc.cm.CM_CaseType = caseType;
                dc.state = "新增";
                dc.cm.CM_ID = Snowflake.GetId().ToString();
                var dialogResult = dc.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    cm = dc.cm;
                    LoadData(xmlPath, caseType, 0);
                    //DataTable dt = new DataTable();
                    //dt.Columns.AddRange(new DataColumn[] { new DataColumn("CM_Code"), new DataColumn("CM_CodeCH"), new DataColumn("AT_Code"), new DataColumn("AT_Name"), new DataColumn("AT_WordsMode"), new DataColumn("CM_ID"), new DataColumn("AT_ID") });
                    //DataRow dr = dt.NewRow();
                    //dr["CM_Code"] = cm.CM_Code;
                    //dr["CM_CodeCH"] = cm.CM_CodeCH;
                    //dr["AT_Code"] = cm.AT_Code;
                    //dr["AT_Name"] = cm.AT_Name;
                    //dr["AT_WordsMode"] = cm.AT_WordsMode;
                    //dr["CM_ID"] = cm.CM_ID;
                    //dr["AT_ID"] = cm.AT_ID;
                    //dt.Rows.Add(dr);
                    //dgvArgumentTypeConfig.DataSource = dt; //dc.rm
                    //dgvArgumentConfig.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(cm.AT_ID);
                }
            }
            else if (cbxConvertModeConfig.SelectedIndex == 1)
            {
                ArgumentConfigNew dc;
                if (dgvArgumentTypeConfig.Rows.Count > 0)
                {
                    //cmCCode="",string cmCCodeCH
                    string cmCCode = dgvArgumentTypeConfig.Rows[0].Cells["CM_CodePZ"].Value.ToString();
                    string cmCCodeCH = dgvArgumentTypeConfig.Rows[0].Cells["CM_CodeCHPZ"].Value.ToString();
                    dc = new ArgumentConfigNew(1, true);
                    dc.cm = new ConvertMode();
                    dc.cm.CM_XmlPath = xmlPath;
                    dc.cm.CM_Custom = 0;
                    dc.cm.CM_CaseType = caseType;
                    dc.cm.CM_Code = cmCCode;
                    dc.cm.CM_CodeCH = cmCCodeCH;
                    dc.state = "新增";
                    dc.cm.CM_ID = dgvArgumentTypeConfig.Rows[0].Cells["CM_IDConfigZD"].Value.ToString();
                }
                else
                {
                    //案由字典值配置
                    dc = new ArgumentConfigNew(1);
                    dc.cm = new ConvertMode();
                    dc.cm.CM_XmlPath = xmlPath;
                    dc.cm.CM_Custom = 0;
                    dc.cm.CM_CaseType = caseType;
                    dc.state = "新增";
                    dc.cm.CM_ID = Snowflake.GetId().ToString();
                }
                var dialogResult = dc.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    LoadData(xmlPath, caseType, 1);
                    //if (cbxConvertModeConfig.SelectedIndex == 0)
                    //{
                    //    cm = dc.cm;
                    //    LoadData(xmlPath, caseType, 0);
                    //    //DataTable dt = new DataTable();
                    //    //dt.Columns.AddRange(new DataColumn[] { new DataColumn("CM_Code"), new DataColumn("CM_CodeCH"), new DataColumn("AT_Code"), new DataColumn("AT_Name"), new DataColumn("AT_WordsMode"), new DataColumn("CM_ID"), new DataColumn("AT_ID") });
                    //    //DataRow dr = dt.NewRow();
                    //    //dr["CM_Code"] = cm.CM_Code;
                    //    //dr["CM_CodeCH"] = cm.CM_CodeCH;
                    //    //dr["AT_Code"] = cm.AT_Code;
                    //    //dr["AT_Name"] = cm.AT_Name;
                    //    //dr["AT_WordsMode"] = cm.AT_WordsMode;
                    //    //dr["CM_ID"] = cm.CM_ID;
                    //    //dr["AT_ID"] = cm.AT_ID;
                    //    //dt.Rows.Add(dr);
                    //    //dgvArgumentTypeConfig.DataSource = dt; //dc.rm
                    //    //dgvArgumentConfig.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(cm.AT_ID);
                    //}
                    //else if (cbxConvertModeConfig.SelectedIndex == 1)
                    //{
                    //    cm = dc.cm;
                    //    LoadData(xmlPath, caseType,1);
                    //}
                }
            }
        }

        public void LoadData(string xmlPath, string caseType, int configType)
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[] { new DataColumn("CM_Code"), new DataColumn("CM_CodeCH"), new DataColumn("AT_Code"), new DataColumn("AT_Name"), new DataColumn("AT_WordsMode"), new DataColumn("CM_ID"), new DataColumn("AT_ID"), new DataColumn("AR_ID"), new DataColumn("AR_CauseCode") });
            DataTable argumentTable = new DataTable();
            //0案件字典1案由字典
            if (configType == 0)
            {
                argumentTable = convertModelBll.GetConvertModeData(xmlPath, caseType);
                dgvArgumentTypeConfig.Columns["AR_CauseCode"].Visible = false;
            }
            else if (configType == 1)
            {
                argumentTable = argumentRelBll.GetConvertModeData(xmlPath, caseType);
                dgvArgumentTypeConfig.Columns["AR_CauseCode"].Visible = true;
            }
            if (argumentTable != null && argumentTable.Rows.Count > 0)
            {
                foreach (DataRow item in argumentTable.Rows)
                {
                    DataRow dr = dt.NewRow();
                    dr["CM_Code"] = item["CM_Code"].ToString();
                    dr["CM_CodeCH"] = item["CM_CodeCH"].ToString();
                    dr["AT_Code"] = item["AT_Code"].ToString();
                    dr["CM_ID"] = item["CM_ID"].ToString();
                    dr["AT_ID"] = item["AT_ID"].ToString();
                    dr["AT_Name"] = sysArgumentTypeData.Select("AT_ID='" + dr["AT_ID"] + "'")[0]["AT_Name"].ToString(); ;
                    dr["AT_WordsMode"] = sysArgumentTypeData.Select("AT_ID='" + dr["AT_ID"] + "'")[0]["AT_WordsMode"].ToString();
                    dr["AR_ID"] = item["AR_ID"].ToString();
                    dr["AR_CauseCode"] = string.IsNullOrEmpty(item["AR_CauseCode"].ToString().Trim()) ? "" : sysCaseCauseTable.Select(" ID='" + item["AR_CauseCode"].ToString() + "'")[0]["Name"].ToString();
                    dt.Rows.Add(dr);
                }
                dgvArgumentTypeConfig.DataSource = dt; //dc.rm
                dgvArgumentConfig.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(dt.Rows[0]["AT_ID"].ToString());
            }
            else
            {
                PublicMethod.ClearDataGridViewData(dgvArgumentConfig);
                PublicMethod.ClearDataGridViewData(dgvArgumentTypeConfig);
            }
        }

        /// <summary>
        /// 修改字典值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e)
        {

            if (dgvArgumentTypeConfig.Rows.Count == 1)
            {
                string xmlPath = clicknodeConfig.FullPath;
                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                ArgumentConfigNew dc = new ArgumentConfigNew(cbxConvertModeConfig.SelectedIndex);
                DataTable dt1 = (DataTable)dgvArgumentTypeConfig.DataSource;
                string atId = dt1.Rows[0]["AT_ID"].ToString();
                dc.cm = new ConvertMode();
                if (dgvArgumentTypeConfig.Rows[0].Cells["CM_IDConfigZD"].Value != null && !string.IsNullOrEmpty(dgvArgumentTypeConfig.Rows[0].Cells["CM_IDConfigZD"].Value.ToString()))
                {
                    dc.cm.CM_ID = dgvArgumentTypeConfig.Rows[0].Cells["CM_IDConfigZD"].Value.ToString();
                }
                dc.state = "修改";
                dc.cm.CM_Code = dgvArgumentTypeConfig.Rows[0].Cells["CM_CodePZ"].Value.ToString();
                dc.cm.CM_CodeCH = dgvArgumentTypeConfig.Rows[0].Cells["CM_CodeCHPZ"].Value.ToString();
                dc.cm.AT_Name = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Name"].ToString();
                dc.cm.AT_Code = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Code"].ToString();
                dc.cm.AT_ID = atId;
                dc.cm.AT_WordsMode = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_WordsMode"].ToString();
                dc.cm.CM_XmlPath = xmlPath;
                dc.cm.CM_CaseType = caseType;


                dc.arm = new ArgumentRelModel();
                dc.arm.CM_ID = dc.cm.CM_ID;
                dc.arm.AT_ID = atId;
                dc.arm.AR_ID = dgvArgumentTypeConfig.Rows[0].Cells["AR_ID"].Value.ToString();
                dc.arm.AT_Code = dc.cm.AT_Code;
                dc.arm.AR_CaseType = caseType;
                dc.arm.AR_CauseCode = dgvArgumentTypeConfig.Rows[0].Cells["AR_CauseCode"].Value.ToString();

                var dialogResult = dc.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    PublicMethod.ClearDataGridViewData(dgvArgumentTypeConfig);
                    cm = dc.cm;
                    LoadData(xmlPath, caseType, cbxConvertModeConfig.SelectedIndex);
                    //DataTable dt = new DataTable();
                    //dt.Columns.AddRange(new DataColumn[] { new DataColumn("CM_Code"), new DataColumn("CM_CodeCH"), new DataColumn("AT_Code"), new DataColumn("AT_Name"), new DataColumn("AT_WordsMode"), new DataColumn("CM_ID"), new DataColumn("AT_ID") });
                    //DataRow dr = dt.NewRow();
                    //dr["CM_Code"] = cm.CM_Code;
                    //dr["CM_CodeCH"] = cm.CM_CodeCH;
                    //dr["AT_Code"] = cm.AT_Code;
                    //dr["AT_Name"] = cm.AT_Name;
                    //dr["AT_WordsMode"] = cm.AT_WordsMode;
                    //dr["CM_ID"] = cm.CM_ID;
                    //dr["AT_ID"] = cm.AT_ID;
                    //dt.Rows.Add(dr);
                    //dgvArgumentTypeConfig.DataSource = dt;
                    //dgvArgumentConfig.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(cm.AT_ID);
                }
                else if (dialogResult == DialogResult.No && string.IsNullOrEmpty(dc.cm.CM_Code))
                {
                    MessageBox.Show("请将字典值配置完整！");
                    return;
                }
            }
            else if (dgvArgumentTypeConfig.Rows.Count > 1)
            {
                string xmlPath = clicknodeConfig.FullPath;
                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                ArgumentConfigNew dc = new ArgumentConfigNew(cbxConvertModeConfig.SelectedIndex);
                string atId = dgvArgumentTypeConfig.SelectedRows[0].Cells["AT_IDConfig"].Value.ToString();
                dc.cm = new ConvertMode();
                dc.cm.CM_ID = dgvArgumentTypeConfig.SelectedRows[0].Cells["CM_IDConfigZD"].Value.ToString();
                dc.state = "修改";
                dc.cm.CM_Code = dgvArgumentTypeConfig.SelectedRows[0].Cells["CM_CodePZ"].Value.ToString();
                dc.cm.CM_CodeCH = dgvArgumentTypeConfig.SelectedRows[0].Cells["CM_CodeCHPZ"].Value.ToString();
                dc.cm.AT_Name = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Name"].ToString();
                dc.cm.AT_Code = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_Code"].ToString();
                dc.cm.AT_ID = atId;
                dc.cm.AT_WordsMode = sysArgumentTypeData.Select("AT_ID='" + atId + "'")[0]["AT_WordsMode"].ToString();

                dc.arm = new ArgumentRelModel();
                dc.arm.CM_ID = dc.cm.CM_ID;
                dc.arm.AT_ID = atId;
                dc.arm.AR_ID = dgvArgumentTypeConfig.SelectedRows[0].Cells["AR_ID"].Value.ToString();
                dc.arm.AT_Code = dc.cm.AT_Code;
                dc.arm.AR_CaseType = caseType;
                dc.arm.AR_CauseCode = dgvArgumentTypeConfig.SelectedRows[0].Cells["AR_CauseCode"].Value.ToString();

                var dialogResult = dc.ShowDialog();
                if (dialogResult == DialogResult.Yes)
                {
                    PublicMethod.ClearDataGridViewData(dgvArgumentTypeConfig);
                    cm = dc.cm;
                    LoadData(xmlPath, caseType, cbxConvertModeConfig.SelectedIndex);
                }
            }
            else
            {
                MessageBox.Show("没有需要修改的字典值数据");
                return;
            }
        }


        /// <summary>
        /// 字典值删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {

            if (dgvArgumentTypeConfig.Rows.Count == 1)
            {
                if (MessageBox.Show("确认要删除数据吗？", "此删除不可恢复", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    if (dgvArgumentTypeConfig.Rows[0].Cells["CM_IDConfigZD"].Value != null && !string.IsNullOrEmpty(dgvArgumentTypeConfig.Rows[0].Cells["CM_IDConfigZD"].Value.ToString()))
                    {
                        string cmID = dgvArgumentTypeConfig.Rows[0].Cells["CM_IDConfigZD"].Value.ToString();
                        string arID = dgvArgumentTypeConfig.SelectedRows[0].Cells["AR_ID"].Value.ToString();
                        if (convertModelBll.ConvertModeDeleteConfig(cmID) && argumentRelBll.ArgumentRelDelete(arID))
                        {
                            MessageBox.Show("删除成功！");
                        }
                        else
                        {
                            MessageBox.Show("删除失败！");
                        }
                    }
                    PublicMethod.ClearDataGridViewData(dgvArgumentConfig);
                    PublicMethod.ClearDataGridViewData(dgvArgumentTypeConfig);
                }
            }
            else if (dgvArgumentTypeConfig.Rows.Count > 1)
            {
                string arID = dgvArgumentTypeConfig.SelectedRows[0].Cells["AR_ID"].Value.ToString();
                if (argumentRelBll.ArgumentRelDelete(arID))
                {
                    MessageBox.Show("删除成功！");
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
                string xmlPath = clicknodeConfig.FullPath;
                string caseType = cbTreeViewCaseType.TreeView.SelectedNode.Tag.ToString();
                caseType = sysCaseTypeTable.Select(" ID='" + caseType + "' ")[0]["Code"].ToString();
                LoadData(xmlPath, caseType, 1);
            }
            else
            {
                MessageBox.Show("没有需要删除的数据！");
                return;
            }
        }

        /// <summary>
        /// 字典值数据改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvArgumentTypeConfig_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                string atID = dgvArgumentTypeConfig.Rows[e.RowIndex].Cells["AT_IDConfig"].Value.ToString();
                dgvArgumentConfig.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(atID);
            }
        }

        /// <summary>
        /// 字典值数据改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgvArgumentType_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                string atID = dgvArgumentType.Rows[e.RowIndex].Cells["AT_IDNew"].Value.ToString();
                dgvArgument.DataSource = sysArgumentBll.GetSYS_ArgumentDataByATID(atID);
            }
        }

        /// <summary>
        /// 获取提示内容
        /// </summary>
        /// <returns></returns>
        public bool GetYYLiuCheng()
        {
            string tabName = tabControlModule.SelectedTab.Text;
            Dictionary<string, string> getData = new Dictionary<string, string>();
            if (tabName == "逻辑分段")
            {
                getData.Add("moduleCode", "LdtDataEngin.Moudle.MoudleParagraphExtract");
                getData.Add("moduleName", numbers["Paragraph"][0].ToString());
                getData.Add("processPath", selectLICheng.Substring(1));

            }
            else if (tabName == "案件要素中心")
            {
                getData.Add("moduleCode", "LdtDataEngin.Moudle.MoudleCaseExtract");
                getData.Add("moduleName", numbers["CaseExtraction"][0].ToString());
                getData.Add("processPath", selectLICheng.Substring(1));

            }
            // http://192.168.1.52:10004/api/WordParse/GetReferenceProcess?moduleCode=LdtDataEngin.Moudle.MoudleLawDeduce&moduleName=lawaddnode.xml&processPath=config\processconfig\analysisprocessconfig\a1\drslla\default.xml
            CommonMsgNew2 cm = WebUtil.DoGet<CommonMsgNew2>(url + "api/WordParse/GetReferenceProcess", getData, "gb2312");
            if (cm.result.code == "0")
            {
                tvTxtParagraph.Nodes.Clear();
                tvElementData.Nodes.Clear();
                MessageBox.Show("获取接口数据发生错误：" + cm.result.message);
            }
            else if (cm.result.code == "1")
            {
                List<string> modoules = cm.body;
                StringBuilder sb = new StringBuilder();
                if (modoules.Count > 0)
                {
                    sb.Append("本次操作影响到的流程有：" + "\r\n");
                    foreach (var item in modoules)
                    {
                        sb.Append(sysCaseTypeTable.Select(" Code='" + item.Split('_')[0].Trim() + "' ")[0]["Name"].ToString() + "-" + sysDocTypeTableAll.Select(" Code='" + item.Split('_')[1].Trim() + "'")[0]["Name"].ToString() + "-" + item.Split('_')[2].Trim() + "\r\n");
                    }

                    if (MessageBox.Show(sb.ToString(), "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 查询节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QueryNodeBtn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(QueryNodeTxt.Text.Trim()))
            {
                selectNodes.Clear();
                string tabName = tabControlModule.SelectedTab.Text;
                if (tabName == "逻辑分段")
                {
                    if (cmbCXFS.SelectedIndex == 0)
                    {
                        ParagraphNodeLists.ForEach((x) =>
                        {
                            if (x.Text.Contains(QueryNodeTxt.Text.Trim()))
                            {
                                selectNodes.Add(x);
                            }
                        });
                    }
                    else
                    {
                        string paragraCode = new ExtractFeatureBLL().GetDataBySearchCondition(0, QueryNodeTxt.Text.Trim());
                        if (!string.IsNullOrEmpty(paragraCode))
                        {
                            ParagraphNodeLists.ForEach((x) =>
                            {
                                if (x.Tag.ToString().Split('!')[0] == paragraCode)
                                {
                                    selectNodes.Add(x);
                                }
                            });
                        }
                    }

                }
                else if (tabName == "案件要素中心")
                {
                    if (cmbCXFS.SelectedIndex == 0)
                    {
                        CaseExtractionNodeLists.ForEach((x) =>
                    {
                        if (x.Text.Contains(QueryNodeTxt.Text.Trim()))
                        {
                            selectNodes.Add(x);
                        }
                    });
                    }
                    else
                    {
                        string xmlPath = new ExtractFeatureBLL().GetDataBySearchCondition(1, QueryNodeTxt.Text.Trim());
                        if (!string.IsNullOrEmpty(xmlPath))
                        {
                            CaseExtractionNodeLists.ForEach((x) =>
                            {
                                if (x.FullPath == xmlPath)
                                {
                                    selectNodes.Add(x);
                                }
                            });
                        }
                    }
                }
                if (selectNodes.Count > 0)
                {
                    MaxCount.Text = selectNodes.Count.ToString();//总数
                    CurrentCount.Text = "1";//当前节点条数
                    SkipNumber.Text = CurrentCount.Text;//跳转文本框
                    var CurrNode = Convert.ToInt32(CurrentCount.Text);//当前节点条数
                    LinkIsVisible(CurrNode);//上一条下一条是否可用
                    QueryNode_Page(selectNodes, CurrNode);//定位到目标节点
                }
                else
                {
                    CurrentCount.Text = "0";//没结果
                    SkipNumber.Text = CurrentCount.Text;
                    MessageBox.Show("没有查询到结果！");
                }
            }
            else
            {
                QueryNodeTxt.Focus();
                MessageBox.Show("请输入需要查询的内容后再试！");
                return;
            }
        }



            /// <summary>
            /// 上一条下一条是否可用
            /// </summary>
            /// <param name="CurrNode"></param>
            private void LinkIsVisible(int CurrNode)
            {
                Prelinkbtn.Enabled = true;
                Nextlinkbtn.Enabled = true;
                if (CurrNode <= 1)//当前小于1
                {
                    Prelinkbtn.Enabled = false;//上一页不可用
                }
                if (CurrNode >= selectNodes.Count)
                {
                    Nextlinkbtn.Enabled = false;//下一页不可用
                }
            }

            /// <summary>
            /// 上一条
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void Prelinkbtn_Click(object sender, EventArgs e)
            {
                if (!String.IsNullOrEmpty(CurrentCount.Text))
                {
                    CurrentCount.Text = (Convert.ToInt32(CurrentCount.Text) - 1).ToString();//上一条
                    SkipNumber.Text = CurrentCount.Text;
                    var CurrNode = Convert.ToInt32(CurrentCount.Text);
                    QueryNode_Page(selectNodes, CurrNode);//定位查询
                    LinkIsVisible(CurrNode);
                }
            }

            /// <summary>
            /// 下一条
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void Nextlinkbtn_Click(object sender, EventArgs e)
            {
                if (!string.IsNullOrEmpty(CurrentCount.Text))
                {
                    CurrentCount.Text = (Convert.ToInt32(CurrentCount.Text) + 1).ToString();//下一条
                    SkipNumber.Text = CurrentCount.Text;
                    var CurrNode = Convert.ToInt32(CurrentCount.Text);
                    QueryNode_Page(selectNodes, CurrNode);//定位查询
                    LinkIsVisible(CurrNode);
                }
            }

            /// <summary>
            /// 跳页查询
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void GoQuery_Click_1(object sender, EventArgs e)
            {
                var CurrNode = Convert.ToInt32(SkipNumber.Text);//当前节点条数
                if (selectNodes != null && !string.IsNullOrEmpty(QueryNodeTxt.Text.Trim()))
                {
                    if (selectNodes.Count >= CurrNode)
                    {
                        CurrentCount.Text = SkipNumber.Text;//跳转
                        QueryNode_Page(selectNodes, CurrNode);//定位到目标节点
                        LinkIsVisible(CurrNode);// 上一条下一条是否可用
                    }
                    else
                    {
                        MessageBox.Show("跳转页码有误，重新输入！");
                    }
                }
            }

            /// <summary>
            /// 定位到目标节点
            /// </summary>
            /// <param name="nodes">查询返回结果集</param>
            /// <param name="showindex">第几条</param>
            private void QueryNode_Page(List<TreeNode> nodes, int showindex)
            {
                if (nodes.Count >= showindex && showindex > 0)
                {
                    var NotePidArr = nodes[showindex - 1].Name.Split(',');//所有父级
                    for (var i = 0; i < NotePidArr.Length; i++)
                    {
                        if (i != NotePidArr.Length - 1)
                        {
                            var Node = FindNode(NotePidArr[i]);
                            if (Node != null)
                            {
                                Node.Expand();//拖出所有父级节点
                            }
                        }
                        else  //最后一级节点为查找节点
                        {
                            var node = FindNode(NotePidArr[i]);
                            string tabName = tabControlModule.SelectedTab.Text;
                            if (tabName == "逻辑分段")
                            {
                                tvTxtParagraph.SelectedNode = node;//定位
                            }
                            else
                            {
                                tvElementData.SelectedNode = node;//定位                            
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("跳转页码有误，重新输入！");
                }
            }

            /// <summary>
            /// 查找节点
            /// </summary>
            /// <param name="Nodeid"></param>
            /// <returns></returns>
            private TreeNode FindNode(string Nodeid)
            {
                string tabName = tabControlModule.SelectedTab.Text;
                if (tabName == "逻辑分段")
                {
                    foreach (var node in ParagraphNodeLists)//遍历现在界面上的所有节点
                    {
                        if (node.Name.EndsWith(Nodeid))
                        {
                            return node;
                        }
                    }
                }
                else
                {
                    foreach (var node in CaseExtractionNodeLists)//遍历现在界面上的所有节点
                    {
                        if (node.Name.EndsWith(Nodeid))
                        {
                            return node;
                        }
                    }
                }
                return null;
                //return (TreeNode)NodeList[Nodeid];
            }

        private void chromiumWebBrowser1_LoadingStateChanged(object sender, CefSharp.LoadingStateChangedEventArgs e)
        {
            string f = "";
        }
    }
    public class TreeviewtestFiled : TreeView
        {
            public TreeviewtestFiled()
            {
                this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.EnableNotifyMessage, true);
            }
            protected override void WndProc(ref Message m)
            {
                if (m.Msg == 0x0014) // 禁掉清除背景消息WM_ERASEBKGND

                    return;
                base.WndProc(ref m);
            }
        }

    }
